- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2017 12:40 AM
Hello Experts,
How can we configure Outbound Rest message to send attachment to 3rd party(cloudplus) which later can be used in business rule?
Or is there other way of writing business rule for the same.
Do we need to encode it into Base64 before sending?
I am bit confused.
Any Help would be appreciated.
Thanks
Neeraj Sharma
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2017 02:19 AM
finally i am able to successfully send attachment to 3rd party and viceversa via rest.
Points to Remember.
Sending attachments (serviceNow to 3rd party)
1. Outbound Rest message- Need to ask for a endpoint of the 3rd party. Configure HTTP headers If any.
2. Use this Rest message in the business rule to send attachments
a. Call the rest message and simply send the binary content of the attachment to the request body using function request.setRequestBodyFromAttachment('<attachment sys_id>');
(RESTMessageV2 - setRequestBodyFromAttachment(String attachmentSysId) )
Screenshot of the business rule
And you will see Magic happens.
Receiving attachments (3rd party to serviceNow)
1. Go Rest API explorer > select Attachment API in API name and explore all the APIs available (Get, Post, Delete)
For are two ways of making Post request :-
a) https://yourinstance.service-now.com/api/now/attachment/file
b) https://dev33253.service-now.com/api/now/attachment/upload
table_name = Table name ( incident for above case)
table_sys_id = Unique Id of the record to which attachment needs to be inserted.
file_name = name of the attachment.
In HTTP header you need to send Content-Type Also (Not mandatory but always good to give).
Postman Screenshots
Hope this will be helpful.
Thanks
Neeraj sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2017 12:48 AM
Hi Neeraj,
Yes you will have to encode the attachment in Base64Encoded string.
Code to get the base64 encoded string is below:
Script:
var gr = new GlideRecord('sys_attachment');
gr.addQuery('sys_id', '05be774b4f2a3200fc11fa218110c7cc');
gr.query();
if (gr.next()){
var StringUtil = new GlideStringUtil();
var sa = new GlideSysAttachment();
var binData = sa.getBytes(gr);
var encData = StringUtil.base64Encode(binData);
gs.print(encData);
}
you will have to explore the API as in which parameter you need to send the attachment base64 encoded data
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2017 12:53 AM
Hi Neeraj,
If you don't mind can you share which endpoint you are using and which method.
I assume it should be post method with some content body inside which they must be expecting the attachment data.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2017 02:35 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2017 02:47 AM
Hi Neeraj,
Thanks for the details. Since in Postman you can select the file by browsing it you must be able to send the attachments.
But I think you can send the attachment base64 encoded data in the content body.
I couldn't find any documentation for such api on google. you will have to check the third party team who is responsible to handle the Cloudplus api request. They should help you.
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader