It's all about the answers!

Ask a question

How to get the attachment id of an attachment uploaded using REST API


libin sebastian (1726) | asked Sep 17 '15, 11:30 p.m.
edited Sep 20 '15, 5:31 a.m.
 I have uploaded an attachment using RQMURL utility using command - java -jar RQMUrlUtility.jar -command POST -user <myid> -password <mypath> -filepath "C:\\Users\\libin\Desktop\\abcd.txt" -url "https://localhost:9443/qm/service/com.ibm.rqm.integration.service.IIntegrationService/resources/<project Area>/attachment/<user defined id>"

Attachment is uploaded successfully.But RQM has created a new id for the attachment and hence i am not able to link the attachment to my test case or test results.Is there any way to get the id  assigned by RQM so that i can link it with execution results?

Accepted answer


permanent link
William B Chen (3125) | answered Sep 21 '15, 12:29 p.m.
Hi Libin,

I have followed the suggestion from Paul to issue the GET command in Poster:

GET on https://localhost:9443/qm/service/com.ibm.rqm.integration.service.IIntegrationService/resources/RQMDemo/attachment

It returns the new attachment id from above GET command:

<entry xmlns="http://www.w3.org/2005/Atom"><id>https://localhost:9443/qm/service/com.ibm.rqm.integration.service.IIntegrationService/resources/RQMDemo/attachment/urn:com.ibm.rqm:attachment:31</id><updated>2015-09-21T14:36:27.141Z</updated><title type="text">jazz-mark.png</title><summary type="text">Attachments Section</summary><link href="https://localhost:9443/qm/service/com.ibm.rqm.integration.service.IIntegrationService/resources/RQMDemo/attachment/urn:com.ibm.rqm:attachment:31" rel="alternate" type="application/xml" title=""/>
</entry>

Hope this helps!

Will
libin sebastian selected this answer as the correct answer

Comments
libin sebastian commented Sep 21 '15, 1:51 p.m.

 Hi William,

 Thanks for your update.I tried a GET using the below command -
 java -jar RQMUrlUtility.jar -command GET -user <myid> -password <mypaswd> -filepath I:\Java\junk\ -url "https://localhost:9443/qm/service/com.ibm.rqm.integration.service.IIntegrationService/resources/Demo%20(Quality%20Management)/attachment"

i got the below response -
RQMUrlUtility: Connected to https://localhost:9443 using project "Demo+(Quality+
Management)"
RQMUrlUtility: Calling [ HTTP GET ] method to download an attachment
RQMUrlUtility: Server Response code: 200
RQMUrlUtility: Got an IOException: java.io.FileNotFoundException: I:\Java\junk\M
on, 21 Sep 2015 17:43:15 GMT (The filename, directory name, or volume label synt
ax is incorrect)
 
Directory  I:\Java\junk\ is there in the system.Am i doing something wrong?


Paul Slauenwhite commented Sep 21 '15, 2:01 p.m.
FORUM MODERATOR / JAZZ DEVELOPER

Looks like there is a 'M' appended to the file path:

I:\Java\junk\M

Can you check the -filepath argument?


Donald Nong commented Sep 21 '15, 10:32 p.m. | edited Sep 21 '15, 10:33 p.m.

Paul, the "M" is part of the timestamp "Mon, 21 Sep ...".

Libin, the URL that you used is incorrect and you need to append an attachment ID at the end of the URL. The URL that you used will return a list of all attachments in XML format. The RQM URL Utility is designed in such way that whenever it sees "attachment" in a URL, it will switch to a routine to download the attachment (note that "Calling [ HTTP GET ] method to download an attachment" in the output), and expects a file name returned in the response header so that it can create such a file under the path specified in -filepath. Apparently in your case the file name was empty and the tool was trying to write a stream (the supposed attachment content) to a folder, instead of a file, hence the error.


libin sebastian commented Sep 22 '15, 10:56 a.m.

 Thanks Donald.This is exactly what i was looking for.I am able to download the attachment without any issue.

I have uploaded a file to rqm using below command

java -jar RQMUrlUtility.jar -command PUT -user <myid> -password <mypaswd> -filepath "C:\Users\libin\Desktop\RQMxmls\out.txt" -url "https://localhost:9443/qm/service/com.ibm.rqm.integration.service.IIntegrationService/resources/Demo%20(Quality%20Management)/attachment/<unique id>"

i was able to download the same attachment using below command -

java -jar RQMUrlUtility.jar -command GET -user <myid> -password <mypaswd> -filepath "I:\Java\junk\abcd.txt" -url "https://localhost:9443/qm/service/com.ibm.rqm.integration.service.IIntegrationService/resources/Demo%20(Quality%20Management)/attachment/<unique id used in put command>"

Once again thanks to Donald & Paul for clarifying my doubts


One other answer



permanent link
Paul Slauenwhite (8.3k12) | answered Sep 18 '15, 7:47 a.m.
FORUM MODERATOR / JAZZ DEVELOPER
Yes, it's in the Content-Location response header (see https://jazz.net/wiki/bin/view/Main/RqmApi#HTTP_Responses).  However, the RQM URL Utility does not return the response headers.  You can use a PUT operation with your own external ID (see https://jazz.net/wiki/bin/view/Main/RqmApi#Create) or HTTP Requester/Poster (see https://jazz.net/wiki/bin/view/Main/RqmApi#Common_Usage_Scenarios). 

Note, https://jazz.net/wiki/bin/view/Main/RqmApi#ResourcesFootnote6.



Comments
libin sebastian commented Sep 18 '15, 10:18 a.m. | edited Sep 18 '15, 10:40 a.m.

  I tried with PUT command also.Still i am not able to refer the attachment with user defined id.


Used the below command - 
 java -jar RQMUrlUtility.jar -command PUT -user <myid> -password <mypath> -filepath "C:\Users\libin\Desktop\abcd.txt" -url "https://localhost:9443/qm/service/com.ibm.rqm.integration.service.IIntegrationService/resources/<project Area="">/attachment/<user defined="" id="">"

Can some one give more details on how to get the attachment id?


Paul Slauenwhite commented Sep 20 '15, 2:29 p.m.
FORUM MODERATOR / JAZZ DEVELOPER

The attachment URL (-url value) should be a resource URL (see https://jazz.net/wiki/bin/view/Main/RqmApi#resourceUrl_for_interaction_with) with an ID (see https://jazz.net/wiki/bin/view/Main/RqmApi#id).  The same URL should be used in the GET request.  You can also resolve the attachment resource URL from the attachment feed (see https://jazz.net/wiki/bin/view/Main/RQMURLUtility#Command_Lines_Arguments_explaine). 

I would suggest to use HTTP Requester/Poster (see https://jazz.net/wiki/bin/view/Main/RqmApi#Common_Usage_Scenarios). 

Your answer


Register or to post your answer.