Outbound REST integration using multipart/form-data

Aishwarya59
Tera Contributor

Following is the requirement:

Using an outbound REST based integration, which uses content-type as 'multipart/form-data'......I need to send multiple files and some text data in the payload. 

The authentication is working fine but when it comes to payload, specially the files, the integration breaks.

If anyone has done this before, kindly help here.

Thanks in advance!!

2 REPLIES 2

Tanushree Maiti
Tera Patron

Hi @Aishwarya59 

 

1) Refer KB: KB0745010 How to send Outbound REST request with multipart/form-data 

 

Prerequisite

Multipart/form-data requests are supported only via a REST action step in the IntegrationHub which comes as part of the ServiceNow IntegrationHub plugin. 

Procedure

Once the required plugin is activated, follow the below steps to create the flow.

  1. Navigate to "Flow Designer" in the filter navigator. 
  2. Click on "Designer"
  3. Create a new flow by clicking on "New" and selecting "New Flow"
  4. Enter the Name, Application, Description, Run as user and Submit
  5. Set the trigger conditions as per your requirement. 
  6. Save

The following steps explain how to create the Action.

  1. In the flow designer UI, click on the "+" icon. 
  2. Click on "New Action". 
  3. Enter the required configuration parameters and click on "Submit".
  4. Create a new step here by clicking on the '+' icon under "Action Outline".
  5. In the list of action step options, select "REST" under "Integrations".
  6. Configure the connection details by defining connection inline or by using a connection alias. 
  7. Under Request details, specify the HTTP Method as POST. 
  8. DO NOT set the Content-Type header. The request will break if you set this. The Content-type is automatically set by the REST Step. 
  9. Under Request Content, select the Request type as "Multipart".
  10. Specify the content of a multiple-part request.
    • For each request part, specify its name, content type, and value. The name can be any valid string and the type can be any valid type. The value must match the content type.
    • When Part type File is used the value MUST be the sys_id of the file in the instance. See documentation for more details.
  11. For type, specify the MIME type of the content. For example, application/json, text/plain, etc.
  12. For attachments, set the type and value as given below:
    1. Type: attachment
    2. Value: The Sys ID of the Attachment record containing the content. You can look up this record in a prior step or define it as an input variable.

This completes the setup required for sending outbound REST requests with type multipart/form-data.

  • A sample of how this would look if you sent 2 text fields and one file field are as follows:

     

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

Tanushree Maiti
Tera Patron

@Aishwarya59 

 

ALso you can have a look in following links/posts:

Script to send multipart (including text and binary) RestAPI

https://www.servicenow.com/community/developer-forum/how-to-upload-a-file-in-form-data-format/td-p/3...

https://www.servicenow.com/community/developer-forum/how-to-send-multipart-form-data-from-servicenow...

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti