Send API Multipart attachment to thirdparty

BenG
Tera Guru

Hello,

 

I'am trying to send a API multipart attachment by business rule. I would like to do that without MID server but I have no idea how to do that.

Any idea ?

Thanks for your help

5 REPLIES 5

Ahana 01
Tera Expert

To send a multipart attachment to a third-party system from ServiceNow, you can use the RESTMessageV2 API. Here are the steps:

1. Create a new REST Message in ServiceNow.
- Navigate to System Web Services > Outbound > REST Message.
- Click on New to create a new REST Message.
- Fill in the necessary details like Name, Endpoint, HTTP Method etc.

2. Add HTTP Headers if required by the third-party system.

3. Create a new function in a Script Include or a Business Rule to send the attachment.
- Use the GlideSysAttachment API to get the attachment data.
- Use the RESTMessageV2 API to send the attachment data.

Here is a sample code:

javascript
var attachment = new GlideSysAttachment();
var attachmentGR = attachment.getAttachmentRecord('sys_id_of_attachment');
var restMessage = new sn_ws.RESTMessageV2('rest_message_record', 'http_method');
restMessage.setRequestHeader("Content-Type", "multipart/form-data");
restMessage.setRequestBodyFromAttachment(attachmentGR);
var response = restMessage.execute();


4. Check the response from the third-party system.
- Use the RESTResponseV2 API to get the response data.

Here is a sample code:

javascript
var statusCode = response.getStatusCode();
var responseBody = response.getBody();


5. Handle the response based on your requirements.

Please note that the 'sys_id_of_attachment' should be replaced with the actual sys_id of the attachment you want to send. The 'rest_message_record' and 'http_method' should be replaced with the actual REST Message record and HTTP method you want to use.


nowKB.com

For a good and optimistic result, and solving ServiceNow-related issues please visit this website.https://nowkb.com/home