How to add attachment to JIRA subtask using JIRA API?

Nitin Mane October 21, 2018

 

I am creating JIRA Subtask using the below in POSTMAN:

URL:https://<host>/rest/api/2/issue/

{
"fields":
{
"project":
{
"key": Test"
},
"parent":
{
"key": "Test-123"
},
"summary": "Sub-task of Test-123",
"description": "Don't forget to do this too.",
"issuetype":
{
"id": "5"
}
}
}

 

In the response "key" is generated.

Using the above "key" how do I add attachments to the above subtask created?

what will be the request format?

 

1 answer

1 vote
Matthias Gaiser _K15t_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 21, 2018

Hi @Nitin Mane,

checkout Atlassian's docs on the REST API about adding an attachment to an issue. Adding attachments for subtasks work exactly the same as for other issues with a POST to https://<host>/rest/api/2/issue/{issueIdOrKey}/attachments

BTW: There is also a postman collection with all of the Jira's endpoints.

Cheers,
Matthias.

Nitin Mane October 23, 2018

Hi @Matthias Gaiser (K15t Software)

Thanks for your reply.

 My goal is create subtask, once subtask is created add attachment to it, attachment can be dynamic.

The postman works in the below format to upload an attachment.

set method type to POST.

Then select Body -> form-data -> Enter your parameter name 

and on right side next to value column, there will be dropdown "text, file", select File. choose your image file and post it.

 

Is it possible to in key value format ?Screen Shot 2018-10-23 at 12.55.39 PM.png

Matthias Gaiser _K15t_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 23, 2018

Hi @Nitin Mane,

What do you mean with key value format?

According to the Atlassian docs, you have to send the http request as a multipart/form-data request. And the name of the multipart/form-data parameter that contains the attachments must be file.

I don't think Postman has a more dynamic behaviour for that - but maybe someone else knows more.

Cheers,
Matthias.

Nitin Mane October 23, 2018

Hi Matthias Gaiser

 

I meant how to achieve via RAW text or Json not in form data request, because the image which is uploaded is dynamic.The image and txt file is stored in my local.

Matthias Gaiser _K15t_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 23, 2018

I believe this is not possible. If you want to have a more dynamic behavior, you could script it outside of postman. But you still need to send the request as form data.

Suggest an answer

Log in or Sign up to answer