jira api - add attachment with apollo apollo-datasource-rest or other

Deleted user December 17, 2020

I'm trying to add an attachment to an issue from node with "apollo-datasource-rest".

 

async addIssueAttachment(file) {
// file = {createReadStream, filename, size, mimetype, ... }

await this.post("rest/api/3/issue/{issue}/attachments", {}, {
headers: {
"Authorization": "Basic {key},"
"Content-Type": "multipart/form-data",
"X-Atlassian-Token": "no-check",
"Accept": "*/*"
},
file
});

return true;
}

currently getting this error:

ApolloError: 415: Unsupported Media Type

 How do I send the file?

 Should I use something other than "apollo-datasource-rest"?

 

1 answer

0 votes
Earl McCutcheon
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 18, 2020

Hi @[deleted] ,

An "Error 415 Unsupported Media Type" is going to be related to the content-type header, and indicates An incorrect "Content-Type" or no "Content-Type" (when a content type is required) has been defined for the call.  I think it might be the portion for the content type is simply unneeded in this call so removing the following section would be the first recomended test:

"Content-Type": "multipart/form-data"

As the docs do not reference this as a necessary input for the POST, and I confirmed this works in the following format as a direct CURL command in a test instance.

A quick reference point to the example query in the docks and an additional quick test to see if its a syntax error vs configuration issue vs apollo try running the curl command directly to post the image from the command line referenced in the Documentation at the following links noting that the Jira cloud API uses the <username:API_TOKEN> formatting vs server which uses the <username:password> format:

curl -D- -u user:<API TOKEN> -X POST -H "X-Atlassian-Token: no-check" -F "file=@path/to/myfile.txt" https://your-domain.atlassian.net/rest/api/3/issue/<issue_Key>/attachments

If you run this command are you still getting the same 415 error?

and are you able to remove this section per the Apollo settings?

Regards,
Earl

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events