attachment api in scripted rest api
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2017 10:26 AM
Hi,
I have to create attachment api by using scripted rest api.
Please help me with example.
Thanks
- Labels:
-
Integrations
-
Scripting and Coding
-
Studio
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2017 02:24 PM
Hi Sneha,
The below script should work.
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var hdrs = {},
attachment_sys_id = '1852fd52471321009db4b5b08b9a71a9';
hdrs['Content-Type'] = 'image/jpeg';
response.setStatus(200);
response.setHeaders(hdrs);
var writer = response.getStreamWriter();
var attachmentStream = new GlideSysAttachmentInputStream(attachment_sys_id);
writer.writeStream(attachmentStream);
})(request, response);
Refer Scripted REST API example - streaming file attachments
Hope this helps. Mark the answer as correct/helpful based on impact.
Thanks
Antin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2017 08:58 PM
Hi Antin,
This is for only one sys_id ? What if I have upload multiple documents which inculdes excel aswell moreover how will it get the incident for which I have to upload the document ?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2017 10:15 PM
Hi Sneha,
If you want upload documents into ServiceNow, please refer the below. You may create a Scripted API and use the Attachment API to handle single or multiple files. The script I gave above is to download/GET attachments from ServiceNow.
Attachment API - POST /now/attachment/file
Hope this helps. Mark the answer as correct/helpful based on impact.
Thanks
Antin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2023 02:58 AM - edited ‎06-08-2023 03:43 AM
Hi @antin_s / @Ankur Bawiskar,
The above link is not opening as I also have the requirement to upload the attachment in an incident ticket with its other field values also.
Request you to please guide me in this
Regards,
Shriyansh