Unable to add attachments to a service ticket through JIRA Rest API using Node Js request

Hello,

I was able to add attachment using Postman but when trying to do the same through JIRA Rest API using Node Js request, it does not seem to be working.

I get a status code of 200 but its gives me an empty response and upon checking the JIRA ticket, I couldn’t find the attachment.

Below is a code I am using

var upload = multer({ dest: './jiraAttachments' })
router.post('/uploadAttachments', upload.any(), function (req, response) {
    
    console.log(req.files)
    let fieldNames = JSON.parse(process.env.advisoryDetails)

    var formData = new FormData();
    for(let i=0; i<req.files.length; i++){
        formData.append('file', fs.createReadStream(req.files[i].path))
    }
    
    let formHeaders = formData.getHeaders();
    console.log(formHeaders)

    var options = {
        url: fieldNames.apiEndpointUrl + req.body.key + '/attachments',
        headers: {
            'X-Atlassian-Token': 'no-check',
            ...formHeaders
        },
        auth: {
            user: fieldNames.userId,
            password: fieldNames.password
        },
        data: formData,
        processData: false,
        contentType: false
    }

    request.post(options, function (err, res, body) {
        if (err) {
            console.log(err)
            err['statusCode'] = res.statusCode
            response.send(validation.errorHanlder(err))
        } else {
            console.log('status code', res.statusCode)
            body['statusCode'] = 200
            response.send(body)
        }
    })
})

Here is a screenshot of the console. As you can see I have the file and also the correct headers. It does give me a status code of 200 but as said earlier, the response is empty and there is no attachment added to the ticket.

I have posted the same question in Atlassian community and It’s been like 50 days now and still no response.

I have tried multiple approaches but nothing is working. Any help is appreciated. Thanks!

Hi there! This is a long shot but did you ever find a solution for this? I’m experiencing the exact same issue and am at a loss for what the issue could be. The only difference is I’m not using fs since I’m getting the file data from another HTTP request that’s passed into my application.

That said, creating the fileStream from the exact same file and POST’ing to another app separate from Jira works just fine. Any input you might have would be very much appreciated!