Send Attachments with REST Calls

In this section, you will find out how to send attachments with REST calls.



  1. First, tick the Send Attachments box.
  2. If you would like to send attachments one by one, tick the "Send one by one" option.
  3. Write the name of the form-data parameter name that contains attachments. For instance, in Jira REST API for attachments, this name must be "file" and in ServiceNow REST API, this name must be "uploadFile".
  4. Write a groovy script that returns attachments. These attachments will be sent with the REST Call. If the script is empty, then all attachments will be sent.


Attachment Script
import com.atlassian.jira.component.ComponentAccessor;

import com.atlassian.jira.issue.AttachmentManager;

AttachmentManager attachmentManager = ComponentAccessor.getAttachmentManager();

def attachments = attachmentManager.getAttachments(issue);

return attachments;

Using with Jira

  1. Write the Jira API URL as {Base_Url}/api/2/issue/{issueIdOrKey}/attachments
  2. Select POST as the method.
  3. Jira API requires a special header for this operation. You need to add this header into the header section:

       

      4. Choose a credential that has permission for the operation.

      5. Lastly, type “file” into the parameter name for attachments.


     

For more information, head to: https://docs.atlassian.com/software/jira/docs/api/REST/8.3.0/#api/2/issue/{issueIdOrKey}/attachments

Using with Jira Service Desk

  1. Write the Jira Service Desk API URL as {Base_Url}/rest/servicedeskapi/servicedesk/{serviceDeskId}/attachTemporaryFile
  2. Select POST as the method.
  3. Jira Service Desk API requires a special header for this operation. You need to add this header into the header section:

       

      4. Choose a credential that has permission for the operation.

      5. Lastly, write “file” into parameter name for attachments.


     

For more information, head to: https://docs.atlassian.com/jira-servicedesk/REST/3.6.2/#servicedeskapi/servicedesk/{serviceDeskId}/attachTemporaryFile

Using with ServiceNow

  1. Write ServiceNow API URL as {Base_Url}/api/now/attachment/upload
  2. Select POST as the method.
  3. ServiceNow API requires mandatory values with the request. You can write these values into Request Body as key/value pairs. You can write your own "table_name" and "table_sys_id" values.

       

      4. Choose a credential that has permission for the operation.

      5. Lastly, write “uploadFile” into the parameter name for attachments.

     

Bear in mind that ServiceNow API allows only one attachment per request. So if you need to send more than one attachment, select the "send one by one" option.

For more information, head to: https://developer.servicenow.com/dev.do#!/reference/api/paris/rest/c_AttachmentAPI#attachment-POST-upload