Missed Team ’24? Catch up on announcements here.

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

jira add attachment API returning 400 and 415 error

ORG_Admin_ENSOC_JIRA
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 25, 2024
      const fetch = require('node-fetch');
      const FormData = require('form-data');
      const fs = require('fs');

      const filePath = file.documentPath;
      const form = new FormData();
      const stats = fs.statSync(filePath);
      const fileSizeInBytes = stats.size;
      const fileStream = fs.createReadStream(filePath);

      form.append(file.documentFileName, fileStream, {knownLength: fileSizeInBytes});

      result = await fetch(`${host}/rest/api/3/issue/${issueKey}/attachments`, {
        method: 'POST',
        body:form,
        headers: {
          'Authorization': `Basic ${Buffer.from(
              'Email : API token'
          ).toString('base64')}`,
          'Accept': 'application/json',
          'X-Atlassian-Token': 'no-check',
          'Content-Type': 'application/json'
      }
      }).then((response:any) => {
        console.log("response",response)
        response.json()}).then((jsonResponse:any) => {
        console.log("jsonResponse", jsonResponse)
        return jsonResponse
      });
This is the code for my node.js
Without the 'Content-Type': 'application/json', I am receiving  
status: 400,
statusText: 'Bad Request' 
After adding in the  'Content-Type': 'application/json', I am receiving  
status: 415,
statusText: 'Unsupported Media Type'

0 answers

Suggest an answer

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

Atlassian Community Events