I need to create a ticket with an attachment so that I am using a service desk API to create a ticket. I am able to add an attachment using temporary attachment API
/rest/servicedeskapi/servicedesk/{serviceDeskId}/attachTemporaryFile
It returns
temporaryAttachmentId: 'some unique id'
When I send this temporaryAttachmentId to the ticket creation API
url: /rest/servicedeskapi/request
body params:
{
"raiseOnBehalfOf":"user",
"serviceDeskId":"x",
"requestTypeId":"xxx",
"requestFieldValues":
{
"attachment":["temporaryAttachmentId"]
}
}
the API returns
{"errorMessage":"Your request could not be created. Please check the fields have been correctly filled in. Please reattach all the currently listed attachments","i18nErrorMessage":{"i18nKey":"sd.validation.request.creation.failure.required.field","parameters":["Please reattach all the currently listed attachments"]}}
Why isn't the temporary attachment is not recognized by JIRA when the temporary attachment upload was successful?
Oh! Let me check on my system, if JSD Cloud allow this.
Thanks @DPKJ . We are facing this exception occasionally. Only sometimes we receive this exception that
"Please reattach all the currently listed attachments
There is not a pattern to find the root-cause. We tested the file attachment with the same type of files that received this exception. The attachment was attached successfully.
Give me some time @Arvind I will try and find some time in weekend to run this experiment. Hopefully, I might come up with some solutions.
@Arvind This code seems to be working fine for me.
#!/bin/bash
curl --request POST \
--url https://<SITE>.atlassian.net/rest/servicedeskapi/servicedesk/1/attachTemporaryFile \
--user '<EMAIL>:<TOKEN>' \
--header 'X-Atlassian-Token: nocheck' \
--header 'X-ExperimentalApi: opt-in' \
-F 'file=@"./temp.txt"'
## Once you get ID from above, use it in below
curl --request POST \
--url 'https://<SITE>.atlassian.net/rest/servicedeskapi/request' \
--user '<EMAIL>:<TOKEN>' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{
"serviceDeskId": "1",
"requestTypeId": "1",
"requestFieldValues": {
"summary": "Request JSD help via REST",
"description": "I need a new *mouse* for my Mac",
"attachment": ["77257341-bd38-43a2-9b39-0a6521eabca1"]
}
}'
@DPKJ yes this is what I am doing, it was working fine for me too. The problem here is it was not working some times. We can't able to find the scenario and root cause for this. Once It is failed I reattach the same file and create a ticket, it was created and the attachment is successfully added.
Do you know the possibilities of getting the following error in the ticket creation API response
{"errorMessage":"Your request could not be created. Please check the fields have been correctly filled in. Please reattach all the currently listed attachments","i18nErrorMessage":{"i18nKey":"sd.validation.request.creation.failure.required.field","parameters":["Please reattach all the currently listed attachments"]}}
@Arvind I think temporary attachments doesn't get listed sometimes, it can be some kind of race condition within Jira Cloud system.
I think you should contact Atlassian Support, and check with them if they can confirm this scenario.
Let me put this to Leaders Group, and request Atlassian Team to jump in.
Hello @Arvind
@DPKJ reached out to us to take a look at your question here and you guys are hitting a limitation in the Service desk API, as currently the Service desk add attachment API endpoint allows adding an attachment to an issue that has already been created but does not allow adding the attachment to the issue on the create action. So your specific workaround would require removing the required attachment on the issue create action in the customer portal.
Looking at your API calls the initial add temporary attachment portion of your requests is correct however the follow up post needs to be to a direct issue ID via a:
POST https://INSTANCE.atlassian.net/rest/servicedeskapi/request/ISSUE_ID/attachment
There is some more information on this and we are collecting feedback on the following feature request, please make sure to add a vote to the request and add some details to the request on what your trying to do and how it is impacting you currently to help finalise the attachments REST API:
Regards,
Earl