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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to add Attachment to Jira-SD-Issue via Rest-API

Good morning erveryone. I am tasked with streamlining the Support-Ticket creation. Part of the requirement is to create attachments on newly opened tickets.

Jira-SDs Rest-API requires the user to first upload a file to a servicedesk as a temporary attachment, and then make it permanent by attaching the file to an issue. In my case, the request to attach the file to an issue intermittendly returns HTTP-Code 500 along with the following message:

{"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/temp3914246537425063270",
"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/temp3914246537425063270"]}}

In about 90% of all cases, the request returns statuscode 201 and creates the attachment as expected. Since the AttachmentID is returned from the previous request, my reasoning is that Jira-SD has indeed processed the attachment and assigned it an ID. My questions are:

  1. What is the lifespan of a temporary attachment?
  2. Does Jira-SD limit the number of created attachments per user, per minute?
  3. Does anyone know of a npm-library/package that simplifies interactions with Jira-SD(!!!)s Rest-API?

Thank you very much, i am at a loss.

 

1 answer

0 votes
moofoo Atlassian Team Oct 19, 2020

Hi Jonas,

Thanks so much for your question.

Regarding your questions,

  1. Jira implies 1 hour lifespan on temporary attachments

  2. JSD has no explicit limits on neither REST API calls, nor the number of attachments a user can create

  3. There are no official Atlassian NPM packages that were designed for JSD specifically

That being said, JSD uses Jira internal APIs to create temporary attachments. And when Jira fails to monitor temporary attachment, it throws the exception you have mention. Check out Jira logs for more details and contact Atlassian Support if you require further assistance.

Regarding using JSD REST API on front-end, the way to add temporary attachment is to make a call like this:

$ curl -X POST -d @picture.png http://${JIRA_BASE_URL}/servicedesk/rest/servicedeskapi/servicedesk/1/attachTemporaryFile --header "Content-Type: image/svg+xml" --header "os_username=${USERNAME}" --header "os_password=${PASSWORD}"

Which you can do with Fetch API like this:

const formData = new FormData();

// make sure the formData's field is "file"
formData.append('file', fileData);

fetch(
  `http://${JIRA_BASE_URL}/servicedesk/rest/servicedeskapi/servicedesk/1/attachTemporaryFile`,
  {
    method: 'POST',
    headers: {
      'Content-Type': 'multipart/form-data',
      'Accept': 'application/json',
      'os_username': username,
      'os_password': password,
    },
    body: formData
  }
)
.then(response => response.json())
.then(({ temporaryAttachments }) => temporaryAttachments.map(({ temporaryAttachmentId }) => temporaryAttachmentId));

Then you should use those temporartAttachmentId values to create permanent attachments using the POST /request/${issueKey}/attachment request:

fetch(
  `http://${JIRA_BASE_URL}/servicedesk/rest/servicedeskapi/servicedesk/1/request/${issueKey}/attachment`,
  {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Accept': 'application/json',
      'os_username': username,
      'os_password': password,
    },
    body: JSON.stringify({
      temporaryAttachmentIds: [temporaryId1, temporaryId2],
      _public: true,
    })
  }
);

Thank you,

Artem
Jira Service Desk

PS: if this answer is correct, please click the “Accept answer” button

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira Service Management

Why upgrade to Jira Service Management Premium?

We often have questions from folks using Jira Service Management about the benefits to using Premium. Check out this video to learn how you can unlock even more value in our Premium plan.  &nb...

165 views 0 4
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you