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

How to send a post request to add link to a workitem using oslc.

 Hii,


I am trying to create a link form SystemWeaver Item to CCM in this I am able to link one item with once Workitem but now I need to link more number of items to one work item. Previously I used PUT request to establish a link but when I link a new item with same work item which had an item as a link, it is overridding that link. I need to know how to do this. Below is the sample code using PUT.

Link type is : Related Artificate.

string _putRTCUrl = "/resource/itemName/com.ibm.team.workitem.WorkItem/";
workItemId=54;


HttpWebRequest put_request = (HttpWebRequest)WebRequest.CreateHttp(baseUrl + _putRTCUrl + workItemId);
put_request.Method = "PUT";
put_request.Headers.Add("Authorization", "Basic " + GetEncodedCredentials(UserName, Password));
put_request.Headers.Add("oslc_cm.properties", "dc:type");
put_request.Accept = "application/json";
put_request.ContentType = "application/json";
Console.WriteLine(">> PUT");
Console.WriteLine("Workitem :" + baseUrl + _putRTCUrl + workItemId);
using (var streamWriter = new StreamWriter(put_request.GetRequestStream()))
{
string lable = swId.Name;
string exe = exestingItems;
string requestBody = "{\"rtc_cm:com.ibm.team.workitem.linktype.relatedartifact.relatedArtifact\":[{\"oslc_cm:label\":\""+lable+"\",\"rdf:resource\":\"swap://server3:1768/"+exestingItems+"\"}]}";
streamWriter.Write(requestBody);
}
var httpResponse = (HttpWebResponse)put_request.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var responseText = streamReader.ReadToEnd();
}

can I use POST request to acchive this. If I need to use what are the changes I need to make can any one please suggest me in this.

Thank you,
Regards,
Pavan m.

0 votes



One answer

Permanent link

 What API is this supposed to be? If it is the OSLC API, or the partial representation ( https://jazz.net/library/article/1001 ) it seems to be missing several important headers such as OSLC-CORE-Version, the If-Match header. 


In general the idea of OSLC is, you POST to create a resource. The post body contains all data for the resource. You can only POST once. You also POST to the creation factory and NOT to the resource, as that does not exist and the new resource URI is retuned in the result.

You GET the whole representation and add/remove/change the data as desired (e.g. add a new link to the link collection for a link type) than you PUT all the data to update the resource.

If you do a partial update, I assume the same, so if you add a link type you get the link collection for that link type, add the data for the additional link and PUT all data back.

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: Sep 20 '21, 6:30 a.m.

Question was seen: 606 times

Last updated: Sep 20 '21, 6:58 a.m.

Confirmation Cancel Confirm