We are wanting to add attachments to an existing service desk using the POST API from our React Native application. We are only receiving back "JSON Parse error: Unexpected EOF" from the API. here is our post:
const formData = new FormData();
const fileParts = ["Hello Jira!"];
const blob = new Blob(fileParts, {type : 'text/plain'});
formData.append('image', blob, 'file_name.txt' );
await fetch('https://THING.atlassian.net/rest/servicedeskapi/request/{ID}/attachment', {
method: 'POST',
headers: {
'Authorization' : 'Basic BASE64',
'Content-Type': 'multipart/form-data',
'X-Atlassian-Token': 'no-check'
},
data: formData
})
Hi Jarrod,
Service Desk Cloud does this a bit differently than Jira Core or Jira Software would. This is because Service Desk has some default restrictions as to what the customer can see via the customer portal. The endpoint you're trying to POST to is documented in https://developer.atlassian.com/cloud/jira/service-desk/rest/#api-rest-servicedeskapi-request-issueIdOrKey-attachment-post
From that page:
POST /rest/servicedeskapi/request/{issueIdOrKey}/attachment
This method adds one or more temporary files (attached to the request's service desk using servicedesk/{serviceDeskId}/attachTemporaryFile) as attachments to a customer request and set the attachment visibility using the
public
flag. Also, it is possible to include a comment with the attachments.To get a list of attachments for a comment on the request use servicedeskapi/request/{issueIdOrKey}/comment/{commentId}/attachment.
So in this case, this endpoint can only add a temporary file that has already been uploaded to this issue. That endpoint is not where you actually upload the file itself via REST.
Instead you should first use the POST /rest/servicedeskapi/servicedesk/{serviceDeskId}/attachTemporaryFilePOST endpoint to upload that file. Once that temp file is there, you need to find the Id of that file (which you will see in the response if uploaded successfully, OR you could call the endpoint GET /rest/servicedeskapi/request/{issueIdOrKey}/attachment to see all temp files on that issue). From there you can use your other endpoint to post this attachment, choose public as true if the customer is supposed to see this attachment, and add a comment if you like.
The syntax for that in curl would look like this:
curl --request POST \ --url 'https://your-domain.atlassian.net/rest/servicedeskapi/request/{issueIdOrKey}/attachment' \ --header 'Accept: application/json' \ --header 'Content-Type: application/json' \ --data '{ "temporaryAttachmentIds": [ "temp910441317820424274", "temp3600755449679003114" ], "public": true, "additionalComment": { "body": "Please find the screenshot and the log file attached." } }'
I hope this helps.
Andy
Andy, this is very helpful and we have it already working! Thanks so much!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hey i am getting "sd.attachment.temporary.session.timeout.id" this error - i do get tempid but while uploading attachments it throws this error and if i copy the temp id and upload it through postman it works fine.Strange isn't it
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That is very strange to see. I have not found any other occurrences of this particular error having been reported in any of our support channels. @raveena I would be interested to learn more about the details of your REST call here. Such as
I am interested to try to learn more here, however we might want to create a new question to address that specific problem.
Andy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey Andy,
I'm looking through the documentation on the Service Desk API page and I'm a little confused. When attaching a temporary file onto the service desk there is no example that shows how to actually give a file path. There is a command line example that includes a file path, but nothing for in app use. Am I missing something?
-Alistair
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Alistair,
I'm not sure I have a clear answer for that. I have not built a connect app to perform this action, so it's not clear to me how it might be different. But perhaps one of the coded solutions on this other thread might help shed some light on it https://community.atlassian.com/t5/Jira-Questions/How-do-I-upload-attachment-to-JIRA-Issue-via-REST-API/qaq-p/545073
There are a few different examples there, but granted these are using the Jira Core REST APIs to upload files to Issues. It's not exactly the same as Service Desk adding such files to requests, but it's very close in nature that perhaps these example might help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Andy,
Thanks for your answers on this topic.
Most of the time, we get the following errors when we use attachTemporaryFile before attachment :
{‘errorMessage’: ‘An error occurred while processing the attachment. Could not save attachment to storage: Source file does not exist /var/atlassian/jirahomelocal/caches/tmp_attachments/temp1076873519188975551’, ‘i18nErrorMessage’: {‘i18nKey’: ‘sd.attachment.create.error’, ‘parameters’: [‘Could not save attachment to storage: Source file does not exist /var/atlassian/jirahomelocal/caches/tmp_attachments/temp1076873519188975551’]}}
{‘errorMessage’: ‘There was a problem saving the attachments for this comment’, ‘i18nErrorMessage’: {‘i18nKey’: ‘sd.attachment.temporary.session.time.out.ids’, ‘parameters’: []}}
A lot of them disappear if we add a sleep between attachTemporaryFile and attachment but that's an arbitrary solution so that is not very clean.
Is there a way to ensure that the temporary file has been properly uploaded before to call /rest/servicedeskapi/request/{issueIdOrKey}/attachment ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey @Aymeric Hermant , about how long is your sleep (if you know)? Also, do you know what request status you're getting on the first error call? 400 or 500?
We're also seeing this issue. Most of the time the attachment call works, but sometimes the temporary attachment ids give the message error message you posted.
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am also getting this error on JSM Sandbox, but the same code works fine on regular JSM,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.