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

Jira REST file attachment

swapnildhoke April 1, 2014

I am trying to attach a file to Jira Issue via Rest. I have placed the header as 'X-Atlassian-Token:nocheck'

But I am not able to get the correct structure of xml to attach the file.

It gives me a HTTP 500 error.

Any help?

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Shop Rogers July 11, 2017

Found the solution from Jason to resolve a similar question I had.

https://community.developer.atlassian.com/t/powershell-invoke-restmethod-uploading-new-attachment-to-jira-ticket/6184/3

For all the other googlers out there that may research this in the future, this is how I got this to work for me after editing the code from Jason.

 

THANKS! You're the man Jason.

function Upload-JiraCSV($jiraTicket, $filepath)
{
    $wc = new-object System.Net.WebClient
    $wc.Headers.Add("Authorization", $headers.Authorization)
    $wc.Headers.Add("X-Atlassian-Token", "nocheck") 
    $wc.UploadFile("$URIPath/issue/$jiraTicket/attachments", $filepath)
}
1 vote
Jason Monsorno
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.
April 1, 2014

This is how we do it from PowerShell

function Jira-UploadFile($jiraTicket, $filepath)
{
    $wc = new-object System.Net.WebClient
    $wc.Headers.Add("Authorization", $Global:JIRA_HEADER.Authorization)
    $wc.Headers.Add("X-Atlassian-Token", "nocheck") 
    $wc.UploadFile("$Global:JIRA_BASE_URL/rest/api/latest/issue/$jiraTicket/attachments", $(Resolve-Path $filepath)) > $null
}

Mike October 22, 2014

Hi Jason, is the $filepath local to the JIRA server? or can it be from a remote server where the script is running? the reason I ask, is because I tried your function, but is giving me "Network Path not found" How are you passing the path? I use "D:\something.html"

Jason Monsorno
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.
October 22, 2014

No, the file is on whatever server. The WebClient will put its content into a POST method request. I already have in the script the Resolve-Path which will make relative paths absolute. $Global:JIRA_BASE_URL need to be set to your jira instance with a protocol header, ex: "http://myjira:1234";. The $Global:JIRA_HEADER.Authorization is the Base64 of username:password like all the authorized API calls need.

TAGS
AUG Leaders

Atlassian Community Events