Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

Add comment to work item using API

I'm trying to add new comment to a work item using c#
and I can't make it work.
I get the exception:
The remote server returned an error: (400) Bad Reques

(I'm trying to aviod using CURL)
my code is:

//set URL
HttpWebRequest request =
WebRequest.Create(new Uri("https://192.168.16.14:9443/jazz/oslc/workitems/_LD0j4K2vEd6wr5OgrMF4rQ/rtc_cm:comments")) as HttpWebRequest;

//authentication
request.Referer = this.refererLogIn;
request.CookieContainer = this.cookieContainer;

//Request parameters
request.ContentType = "application/x-oslc-cm-change-request+xml";
request.Accept = "text/xml";
request.Method = "POST";

//Get the XML file to byte
byte[] bytes;
using (FileStream fsSource = new FileStream(@"C:\xmlCommant.xml",
FileMode.Open, FileAccess.Read))
{
// Read the source file into a byte array.
bytes = new byte[fsSource.Length];
int numBytesToRead = (int)fsSource.Length;
int numBytesRead = 0;
while (numBytesToRead > 0)
{
// Read may return anything from 0 to numBytesToRead.
int n = fsSource.Read(bytes, numBytesRead, numBytesToRead);

// Break when the end of the file is reached.
if (n == 0)
break;

numBytesRead += n;
numBytesToRead -= n;
}
}
request.ContentLength = bytes.Length;

//Write to stream
Stream newStream = request.GetRequestStream();
newStream.Write(bytes, 0, bytes.Length);
newStream.Close();

//Error is thrown
HttpWebResponse response = request.GetResponse() as HttpWebResponse;


thanks for any help

0 votes



3 answers

Permanent link
I'm trying to add new comment to a work item using c#
and I can't make it work.
I get the exception:
The remote server returned an error: (400) Bad Reques
(I'm trying to aviod using CURL)
my code is:

400 Bad Request usually contains an error element in the requested format
(XML in your case) that describes the problem in more detail.
Can you check if there is such an error description?

--
Regards,
Patrick
Jazz Work Item Team

0 votes


Permanent link
I'm trying to add new comment to a work item using c#
and I can't make it work.
I get the exception:
The remote server returned an error: (400) Bad Reques
(I'm trying to aviod using CURL)
my code is:

400 Bad Request usually contains an error element in the requested format
(XML in your case) that describes the problem in more detail.
Can you check if there is such an error description?

--
Regards,
Patrick
Jazz Work Item Team

Thanks for your help Patrick
I get the error:

Malformed XML: The prefix "rtc_cm" for element "rtc_cm:Comment" is not bound.

my xml file is(I replace the first '>' char to '
[rtc_cm:Comment rdf:resource="https://192.168.16.14:9443/jazz/oslc/workitems/10/rtc_cm:comments/0">
dc:created>
2009-10-12T12:27:24.170Z
[/dc:created>
[dc:creator rdf:resource="https://192.168.16.14:9443/jazz/oslc/users/_tj6fYK2lEd6wr5OgrMF4rQ" />
[dc:description>
OK
[/dc:description>
[/rtc_cm:Comment>


Regards,
Ronen

0 votes


Permanent link
I found my answer:
the XML file need to get the description of all parameters like "rtc_cm".
I enterd to one of the comments in my work item and copy the parameters.
my xml file need to change to:

[?xml version="1.0" encoding="UTF-8" ?>
[rtc_cm:Comment rdf:resource="https://192.168.16.14:9443/jazz/oslc/workitems/821/rtc_cm:comments/6" xmlns:rtc_cm="http://jazz.net/xmlns/prod/jazz/rtc/cm/1.0/"
xmlns:oslc_disc="http://open-services.net/xmlns/discovery/1.0/"
xmlns:dc="http://purl.org/dc/terms/"
xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/"
xmlns:jp="http://jazz.net/xmlns/prod/jazz/presentation/1.0/"
xmlns:jd="http://jazz.net/xmlns/prod/jazz/discovery/1.0/"
xmlns:oslc_cm="http://open-services.net/xmlns/cm/1.0/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:calm="http://jazz.net/xmlns/prod/jazz/calm/1.0/">
[dc:created>2009-10-11T13:57:47.973Z[/dc:created>
[dc:creator rdf:resource="https://192.168.16.14:9443/jazz/oslc/users/_tj6fYK2lEd6wr5OgrMF4rQ" />
[dc:description>OK[/dc:description>
[/rtc_cm:Comment>

0 votes

Your answer

Register or log in to post your answer.

Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details

Question asked: Oct 12 '09, 11:42 a.m.

Question was seen: 8,423 times

Last updated: Oct 12 '09, 11:42 a.m.

Confirmation Cancel Confirm