How to upload an attachment to a work item via REST API
Hi,
I'm currently working with python to interface with the RTC REST API, and have been having a lot of success so far. I've hit a bit of a problem however in uploading an attachment to a project and linking it to a work item.
I've done plenty of googling on this one and have found a couple of people using java as a solution however this doesn't really help me. The same article mentions REST but in the form of:
So, it should be doable with HTML (not sure about REST), but it is probably not trivial and undocumented.
I've also had a few people say that they have completed this with OSLC version 2.0 however without any details.
Currently I'm using the python requests library and the following is my code (assuming authentication has already taken place):
csrf = ""
With the above I'm getting an error of "invalid post request", not sure what I'm doing wrong but I don't think that I'm that far off.
I've also tried looking at the source of the RQMUtility for uploading attachments without finding out any conclusive differences to what I'm trying to complete here.
Can anyone help?
Cheers,
Hugh
|
Accepted answer
4 other answers
Ralph Schoon (63.5k●3●36●46)
| answered May 13 '14, 3:37 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
I am not aware that there is a public API to do this. This might be out of age knowledge. I know that others have used protocol tracking tools to determine how this is done and successfully coded up solutions. It is apparently a series of requests.
I only know how to do this with the Plain Java API. See https://rsjazz.wordpress.com/2012/08/01/uploading-attachments-to-work-items/ Comments
Hugh McManus
commented May 13 '14, 6:27 p.m.
Hey Ralph,
Thanks for getting back to me on this one, as my question said I've looked at that wordpress blog. Not much help when you can't use java to be honest.
I did manage to get this working and when I get a chance to clean up the code I'll post it on here.
Cheers,
Hugh
Hugh,
|
Hi,
I am using the follwing code to upload files using Lyo Client CM: Utils.java Client.java files=... task=... client=... projectAreaUUID=... urlRTC=... ArrayList<URI> filesURL = new ArrayList<>(); for (File file : files) { URI url = uploadAttachment(file, task, client,urlRTC, projectAreaUUID); filesURL.add(url); } task.getExtendedProperties() .put(new QName(RTC_NAMESPACE, "com.ibm.team.workitem.linktype.attachment.attachment"), filesURL); Comments Hi All,
public void ExecuteMainFlow() { // 1. Get Project area details from work item number -- WG project area >> _Cr9g8F1AEeGx6_jqJZ63AA // Parameter: workItemNumber, Return value: projectArea Console.WriteLine("Getting Project Area Detail"); Console.WriteLine(" PARAMETER: Work Item Number = {0}", MainForm.workItem); string jsonResponse = RunGet(@"https://adtclmamr00303.accenture.com/ccm/oslc/workitems/" + MainForm.workItem + @".json?oslc_cm.properties=rtc_cm:contextId"); var dict = JsonConvert.DeserializeObject<Dictionary<string, dynamic>>(jsonResponse); string projectArea = dict["rtc_cm:contextId"]; Console.WriteLine(" RETURN: Project Area = {0}", projectArea);
// Parameter: projectArea, Return value: attItemID (UUID of attachment) Console.WriteLine("Uploading attachment to Project Area"); Console.WriteLine(" PARAMETER: Project Area = {0}", projectArea); // string attItemId = RunPost(MainForm.urlPost, MainForm.fileAtt); // ***existing attachment hardcoded for testing string attItemId = "_b_CQIKvyEeWaxfv-hWy7tA"; Console.WriteLine(" RETURN: UUID of Attachment = {0}", attItemId);
Console.WriteLine("Adding attachment link to Work Item"); // 3.1 Get JSON response from attachment link Console.WriteLine(" PARAMETER: UUID of attachment = {0}", attItemId); string getResp = RunGet(@"https://adtclmamr00303.accenture.com/ccm/resource/itemOid/com.ibm.team.workitem.Attachment/" + attItemId); // Console.WriteLine(@" RETURN: Attachment ID = {0}, // Attachment Description = {1}", attId,attDesc); // 3.2 Post attachment to Work Item URL // Console.WriteLine(@" PARAMETER: Attachment ID = {0}, // Attachment Description = {1}, // UUID of attachment = {2}", attId, attDesc, attItemId); // RunFinalPost(MainForm.urlFinalPost, attItemId);} See the URI and Payload used for final post. URI: https://host/ccm/oslc/workitems/13615.json?oslc_cm.properties=rtc_cm:com.ibm.team.workitem.linktype.attachment.attachment PAYLOAD: @"{""rdf:resource"": ""https://host/ccm/resource/itemOid/com.ibm.team.workitem.Attachment/_b_CQIKvyEeWaxfv-hWy7tA"", |
Hi guys,
I am currently working on the same issue. I try to upload an attachment using Java (for RTC v6.0.1), without luck. No matter if I am posting the content directly or using Eclipse Lyo with Fernando's solution, I always see "Invalid POST request". It's not a matter of params as an error in the params section leads to an appropriate error message. @fernd.fs: Does your solution work with v6 too? If yes it would be cool to know whether you modified your code in some way. It seems as I am missing something here but right now I don't get it. @hmcmanus could you please post the JSON string you are sending in the body part of the request to the IAttachmentRestService? Regards Michael Comments 1
Donald Nong
commented Feb 21 '16, 7:15 p.m.
It's the consensus that there is no published API for uploading attachments to RTC. What most people try to do (and succeed for some) is monitor the traffic in a browser when uploading an attachment, then replicate the same traffic in their own application (regardless the programming language of choice). This results in using the internal API, which may behave differently across versions.
Ralph Schoon
commented Feb 22 '16, 3:48 a.m.
| edited Feb 22 '16, 4:04 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
The Java API that can be used is explained here:
|
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.