I am trying to create an automated service for Jira where a zip file or .db3 file is uploaded to an existing Jira issue. This is my current code:
var client = new RestClient(".../rest/api/3/issue/"+issueKey);
client.Timeout = -1;
var request = new RestRequest(Method.PUT);
request.AddHeader("Authorization", "Basic ...");
request.AddFile("file", zipPath, "application/zip");
var response = client.Execute(request);
When this request is sent, I receive "StatusCode: UnsupportedMediaType, Content-Type: text/html;charset=UTF-8, Content-Length: -1)" even though the content-type has been set to application/zip, I am not sure what is going wrong here. I know zip files can be uploaded directly into the issue, so it is not an issue with project permissions or custom restrictions. When adding on "/attachments" to the end of the RestClient url, MethodNotAllowed is returned or when "Content-Type" is set to "application/zip", UnsupportedMediaType is also returned. The documentation only talks about image or json files, I have have not seen anything for other file types. Any help here would be appreciated.
I see that you are trying to upload an attachment to a Jira Cloud issue, but are getting an unsupportedmediatype error in the process. I think I can see the problem here. Try removing your header of
If it's still not working, then also remove the header of
I was able to recreate this problem when trying to use the accept header here. I believe it is confusing the media service that accepts file attachments to see these headers in the request. Check out our Jira Cloud REST API reference for this endpoint over in https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-attachments/#api-rest-api-3-issue-issueidorkey-attachments-post it explains in some more details about which header is expected for a call like this, and it looks like your call has two additional unexpected headers here.
I tested this out in my own environment using curl and I found that I could upload attachments with an example like this one:
curl --request POST \
--url 'https://[yourCloudSite].atlassian.net/rest/api/3/issue/SCRUM-33/attachments' \
--header 'Authorization: Basic [redacted]' \
--header 'Content-Type: multipart/form-data' \
--header 'X-Atlassian-Token: no-check' \
I also found that I could remove the header of "content-type" entirely and still successfully upload the file here, but that might also be on account of using the curl client to make this request.
Try adjusting your call to remove these extra headers and let me know if you still run into any problems with this.
Thanks a ton for the help, Andy! Just removing the Content-Type and Accept entirely as headers worked. I only added X-Atlassian-Token as a header along with authorization. I also realized I didn't need to zip the file since it does support uploading .db3. My new code is below:
public void AddJiraAttachments(string issueKey, string filePath)
var client = new RestClient(".../"+issueKey+"/attachments");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
IRestResponse response = client.Execute(request);
Hello Community! Quick disclaimer: We are running a contest on Community (The Atlympics!) from July 23rd - August 8th of 2021. If you are interested in participating in this contest (prizes! ...
Connect with like-minded Atlassian users at free events near you!Find an event
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.Host an event
You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events