Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Can't attach files to JSD customer request using REST API from AWS SAM locally

Sid K September 27, 2022

I'm working with the jira service management rest API to simply submit a customer request on JSD. I am submitting this request using the AWS sam cli in a lambda function.
An attachment is a required field for my request, so I used attachTemporaryFile to get a file id that I can pass to the required field of "attachment", this doesn't result in errors.
I call POST /rest/servicedeskapi/request/{issueIdOrKey}/attachment after my request is created because using a temporary file id in the POST /rest/servicedeskapi/request doesn't show the attachment when I open the ticket on the customer portal.
So I'm using the python requests library to submit a customer request that exists in a service desk, then attach a temporary file to the service desk, and finally attach that temporary file id I get back to the customer request I submitted. 

When I call POST /rest/servicedeskapi/request/{issueIdOrKey}/attachment I get a 500 status code with error:
{"errorMessage":"An error occurred while processing the attachment. Could not save attachment to storage: Source file does not exist /var/atlassian/application-data/jira/caches/tmp_attachments/temp5549853747651003221","i18nErrorMessage":{"i18nKey":"sd.attachment.create.error","parameters":["Could not save attachment to storage: Source file does not exist /var/atlassian/application-data/jira/caches/tmp_attachments/temp5549853747651003221"

these are my headers for /rest/servicedeskapi/request/{issueIdOrKey}/attachment

    headers = {
    "Authorization": "Bearer <token>",
    "X-Atlassian-Token": "no-check",
    "X-ExperimentalApi": "opt-in"
    }
and this is the payload for the request:
    payload = json.dumps({
        "temporaryAttachmentIds": [
        "temp5549853747651003221",
        ],
        "public": "true",
        "additionalComment": {
            "body": "sample body"
        }
    })
response =  requests.request("POST", url=f'<baseUrl>/rest/servicedeskapi/request/{issue_id}/attachment', data=payload, headers=headers)
I am getting 201 responses for attachTemporaryFile and my customer request (
rest/servicedeskapi/request). Also, I can successfully use the /rest/servicedeskapi/request/{issueIdOrKey}/attachment when I call the requests without a lambda function. How can I resolve this issue, it doesn't make sense that I'm getting a temporary file id back (with attachTemporaryFile) that doesn't exist when I want to add it to my customer request. 

1 answer

1 accepted

3 votes
Answer accepted
Sid K September 28, 2022
It works when I retry the POST    
while True:
        try:
            create_attachment_response = requests.request(
                "POST",
                url=f'https://<baseURL>/rest/servicedeskapi/request/{issue_id}/attachment',
                data=file_payload,
                headers=create_attachment_header
            )
            create_attachment_response.raise_for_status()            
            break
        except:
            continue
Mark M September 28, 2022

Cool!

John Crawford October 22, 2022

So how do I access all this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events