- 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: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:50 AM
could you please check this .It is not working . I tried for both incident and attachment table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2023 01:54 AM
Hi @ nandika 1 ,
Put logs and check what exactly you are getting
var responseBody = response.getBody();
var getstatus=response.getStatusCode();
gs.log('Statuscode'+getstatus);
gs.log('ResponseBody'+responseBody);
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2023 11:41 PM - edited 12-14-2023 11:46 PM
Hi @Anand Kumar P I think its issue with my rest .can you please tell me how to solve this issue