- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2020 06:09 AM
Hello,
Is there a way to return a binary file as output from a scripted rest API?
The file is returned from another endpoint.
I want to achieve something similar to what GlideSysAttachment().getContentStream(sys_id) and response.getStreamWrite allow.
In this case, the source file is the response from a RESTMessageV2 GET call.
I can't find a way to set the response body from the binary content.
Thanks!
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2020 09:03 PM
This post solved my problem:
https://community.servicenow.com/community?id=community_question&sys_id=f0b60b65db1cdbc01dcaf3231f96...
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2020 06:20 AM
check below link should help you
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
10-09-2020 06:29 AM
Thanks Ankur,
I need the file to be returned from a SNOW scripted REST API. I am getting the content of the file using a RESTMessageV2 call (inside the SNOW script). I'm not using an external rest call like it's mentioned in the link you provided.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2020 09:03 PM
This post solved my problem:
https://community.servicenow.com/community?id=community_question&sys_id=f0b60b65db1cdbc01dcaf3231f96...
Regards,

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2020 09:07 PM
If the binary file is an attachment, I've posted Scripted REST API code to download the file in the following thread.
EDIT: ServiceNow ended a way to zip files and download. This may be because zipping file is CPU and memory intensive so if many users do it at once, it may impact performance on an instance. However, it may be possible to zip the current attachments to create a new attachment file and then download that.