- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā12-07-2023 11:49 PM
Hi
I want to send attachment through Rest Api.can anyone please help me on it .Kindly guide on how to write the rest api and business rule for it
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā12-08-2023 12:07 AM - edited ā12-08-2023 12:09 AM
Hi @ nandika 1 ,
Use below script in business rule to sent attachment to third party api
var attachmentid = '';
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_sys_id", current.getValue('sys_id'));
gr.query();
if (gr.next()) {
attachmentid = gr.getValue('sys_id');//getting attachent sys_id
}
var tosend = JSON.stringify(body);
var request = new sn_ws.RESTMessageV2('Ottos test instance', 'Otto_Post');
request.setRequestHeader("Accept", "application/json");
request.setRequestHeader('Content-Type', 'application/json');
request.setRequestBody(tosend);
request.setRequestBodyFromAttachment(attachmentid);//setting attachment ot thirdparty
request.setWorkflow(false); //attempt to stop loops
var response = request.execute();
var responseBody = response.getBody();
var json = responseBody;
var obj = JSON.parse(json); //define JSON parsing for the response JSON file to decode
Mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā12-08-2023 12:46 AM
Hi @ nandika 1
You can refer to below thread , I have used it before to send attachments through REST API