I am trying to attach a txt file from my local computer to Jira issue using Invoke-Restmethod and i am getting following error
Invoke-RestMethod : The remote server returned an error: (415) Unsupported Media Type.
At C:\scripts\jira4.ps1:30 char:15
+ $newstatus = Invoke-RestMethod -Method POST -Headers $headers -ContentType "tex ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
I am using following command to run it
$newstatus = Invoke-RestMethod -Method POST -Headers $headers -ContentType "text/html;charset=UTF-8" -InFile $ticketfile -uri "$target/rest/api/2/issue/$key/attachments"
No matter what i change for "Contenttype" i still get the same error.
Hi Rajiv,
This seems to be a development related question. With the launch of the new community, the developer community has been split from this community. You will probably have more luck finding an answer if you as it there.
To not leave you empty handed I think you should change the ContentType header to multipart/form-data as that's what the JIRA REST documentation says.
Best,
Maarten
Thanks Maarten
when i change contenttype to Multipart/form-data i get the following error:
Invoke-RestMethod : The remote server returned an error: (404) Not Found.
At C:\scripts\jira4.ps1:30 char:15
+ $newstatus = Invoke-RestMethod -Method POST -Headers $headers -ContentType "mul ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Even when i use curl command i get following response but nothing attached to my jira task
PS C:\Users\rajiv.sharma> curl -D- -u admin:admin -X POST -H "X-Atlassian-Token: no-check" -F "file=@c:\scripts\myfile.txt" http://jira/rest/api/2/issue/key/attachments
HTTP/1.0 302 Found
Location: https://jira/rest/api/2/issue/key/attachments
Server: BigIP
Connection: Keep-Alive
Content-Length: 0
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rajiv,
Unfortunately I don't have too much experience with the REST API.
According to the docs: Returned if the requested issue is not found, the user does not have permission to view it, or if the attachments exceeds the maximum configured attachment size.
A 302 unfortunately is not documented but could be returned by either the apache, nginx or in your case BigIP, your load balancer, in front of JIRA.
So maybe look into that or head over to the Developer Community as it contains more technical experienced Atlassian Users and Developers. :-)
Sorry I couldn't help.
Best,
Maarten
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.