Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Add attachment to Test Execution using ZAPI

Joseph Van Der Wee March 2, 2014

Has anyone had any success adding an attachment to a Zephyr Test Execution using ZAPI? Have noticed the following POST in the API but the documentation for it is not particularly helpful.

Add Attachment by Entity:

/jira_server/rest/zapi/latest/attachment{?entityId, entityType}

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
Daniel
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 5, 2014

Hi Joseph,

Thank you for the question. While we try and keep our documentation up-to-date, the current ZAPI documentation is still in it's first version and will be updated soon with better information in some areas - including this one.

Now, to update an attachment via ZAPI, there are some requirements.

1) entityType

This is the item you will be attaching to. Currently the only types are 'Execution' and 'TestStepResult'

2) entityId

This is the actual Id of the item whose type you chose. If it is an Execution type, you will need a 'scheduleId'. If it is a TestStepResult, you will need a 'testStepId'

The CURL for adding an attachment via ZAPI is formatted as:

curl -D- -u <username>:<password> -X POST -H "X-Atlassian-Token: nocheck" -F "file=@name_map.jpg"  "http://192.168.100.144:9122/rest/zapi/latest/attachment?entityId=<entityId>&entityType=<entityType>"

Note: "X-Atlassian-Token: nocheck" is required

For sample code in Python of attaching to a entity of type 'Execution', please see our Community Forum post here:

http://community.yourzephyr.com/viewtopic.php?f=21&t=1382

Regards,

Daniel

Peter Wilson October 20, 2014

Thanks!! any chance of a PHP example?

Deleted user April 24, 2015

This does not work I get unsupported media type which is incorrect because i can attach it through the browser

Like janardhanan19 likes this
Jaideep Srivastava April 2, 2018

I am using ZAPI to make get,post and put requests through groovy code and read data/update JIRA. While get and put requests are working fine via groovy code, i am facing issue in adding an attachment (Text File). Below is the code -

def attachmentRestUrl = new RESTClient("https://jira-XXXXXXXXXXX/rest/zapi/latest/attachment?entityId=993118&entityType=execution")
def emptyHeadersAttachment = [:]

//emptyHeadersAttachment."Content-Type" = "application/json"
//emptyHeadersAttachment."Accept"="application/json"emptyHeadersAttachment."Authorization"="Basic DDDDDDDDD5nZ19RQVVDAKDALJDAyIUJ4ZGQwVWRPYUo="emptyHeadersAttachment."X-Atlassian-Token"="nocheck"
def responseAttach = attachmentRestUrl.post(   headers: emptyHeadersAttachment,   body : [ file : 'C:\test.txt' ]
 //    contentType: JSON
 //  requestContentType: JSON
//}
)

I tried multiple options like multipart/form-body,changing requestcontenttype but getting "HTTPResponseException". Please note that same operation i am able to achieve using POSTMAN and cURL and tried multiple options with commenting/uncommenting sections. Please help with a groovy code for adding attachment, thanks

Rodrigo Campos Tapia December 20, 2018

tienes algun ejemplo en postman? o codigo java?

TAGS
AUG Leaders

Atlassian Community Events