Forums

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

No attachments found when uploading files through SD API

Keeper May 11, 2020

I'm trying to upload a file through Jira Service Desk's API using the /servicedeskapi/servicedesk/{serviceDeskId}/attachTemporaryFile method as described here: https://docs.atlassian.com/jira-servicedesk/REST/3.9.1/#servicedeskapi/servicedesk/{serviceDeskId}/attachTemporaryFile . This is my code:

<?php

$fileToUpload = '/var/www/html/test.txt';

$cFile = new CURLFile($fileToUpload, 'text/plain', 'test.txt');

$headers = [
'Accept: application/json',
'Authorization: Basic ....',
'X-Atlassian-Token: no-check',
'Content-Type: multipart/form-data',
'X-ExperimentalApi: opt-in',
'Content-Length: '.filesize($fileToUpload)
];

$post = array('file' => $cFile);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://example.com/rest/servicedeskapi/servicedesk/27/attachTemporaryFile');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

$result = curl_exec($ch);

curl_close($ch);

However, I keep getting the following error message:

{"errorMessage":"No attachments found.","i18nErrorMessage":{"i18nKey":"sd.attachment.empty.error","parameters":[]}}

With a 400 HTTP status code in response.

What am I missing? I read it might have something to do with rfc2388 but I couldn't figure out what the issue is.

 

Thanks.

1 answer

1 accepted

0 votes
Answer accepted
Keeper May 11, 2020

Alright, I solved it by removing the content-length header.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events