We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

send attachment in RESTMessageV2

Michael Culhan1
Mega Sage

I'm trying to send an attachment to a third party service (DocParser) in order to extract the text via OCR and return back structured data.

The api documentation for DocParser says to use form-data in the body with file_content as they key and the file content in base64 encoding as the value.  How can I achieve this with the RESTMessageV2 ?  I can get the base64 encoding (GlideSysAttachment.getContentBase64()), but I can't figure out how to put this into the body using form-data.  setRequestBody seems to be for strings and setRequestBodyFromAttachment changes the whole body to binary.  Thanks in advance!

 

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron

@Michael C 

you can send multi-part form data via Rest Message

refer below links

Multipart/form-data attachment pusg using Rest API from Snow->Jira

Outbound REST - Multipart/form-data

Outbound REST - Multipart/form-data

REST API attachments Transfer to JIRA

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

2 REPLIES 2

Deepen Shah
Kilo Guru
 

Hi Michael

You can pass that as String only. For e.g

var json = {};
json['file_content'] = "<base64_data>";

var restMessage = new sn_ws.RESTMessageV2();

restMessage.setRequestBody(JSON.stringify(json));

Try this and let us know.

 

Regards
Deepen shah
aavenir.com

 

Ankur Bawiskar
Tera Patron

@Michael C 

you can send multi-part form data via Rest Message

refer below links

Multipart/form-data attachment pusg using Rest API from Snow->Jira

Outbound REST - Multipart/form-data

Outbound REST - Multipart/form-data

REST API attachments Transfer to JIRA

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader