Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Problem creating attachment in issue via API

Roberto Teresa
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!
October 20, 2023

Im trying to create an attachment in Jira via API using this code but Im getting error 404 not found

 

   const endpoint = `/rest/api/2/issue/${jiraIssue.key}/attachments`;

    const FormData = require('form-data');

    cy.fixture('../../'+filePath, 'binary').then((fileBin) => {

      const blob = Cypress.Blob.binaryStringToBlob(fileBin);

      const formData = new FormData();

      formData.append('file', blob, { filename: 'issue.feature' });

      for (let [key, value] of formData.entries()) {

        console.log(key, value);

      }

      cy.request({

        method: 'POST',

        url: `${this.apiUrl}${endpoint}`, // baseUrl is prepend to URL

        body: formData,

        headers: {

          Authorization: `Basic ${this.apiKey}`,

          'Content-Type': 'text/plain',

          'X-Atlassian-Token': 'no-check',

        }

      }).then(response => {

         if (response.status === 204) {
          console.log(`Response: ${response.status} ${response.statusText}`);
        }


      });

1 answer

0 votes
Fabio Racobaldo _Catworkx_
Community Champion
October 20, 2023

Hi @Roberto Teresa and welcome,

please take a look here https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-attachments/#api-rest-api-3-issue-issueidorkey-attachments-post

it seems that you are using version 2 and not version 3.

Hope this helps,

Fabio

Roberto Teresa
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!
October 20, 2023

Nothing it didn't worked

Fabio Racobaldo _Catworkx_
Community Champion
October 20, 2023

@Roberto Teresa the end poit should contain you instance URL. Something like : "https://XXXX.atlassian.net/jira/rest/api/3/issue/{issueIdOrKey}/attachments"

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events