Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,323,606
Community Members
 
Community Events
168
Community Groups

Jira REST file attachment

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

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)
}

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
}

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"

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
Community showcase
Published in Apps & Integrations

4 Amazing Product and Project Management Apps compete for Best App Demo in July Appy Hours 🥳

Thanks so much to everyone who joined for our July Appy Hours! Product and project management presenter highlights  Checkout - Procurement and asset manager, presented by @Vincent Mutambuki ...

90 views 1 8
Read article

Atlassian Community Events