How do attach file with incident in service now using rest api?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2017 05:50 AM
How do attach file with incident using rest api like jsonv2/table api.? Please help
- Labels:
-
Integrations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2017 07:57 AM
Hello,
A little more information would be useful, such as what version of ServiceNow you're on and some more details about what you're trying to do, but I'll do my best to help, and hopefully it's relevant to what you're looking for. 🙂
Assuming you're on one of the latest versions, there is actually a REST "Attachment API" built-in.
Here is an example snippet from my instance:
var restRequestBody = "YOUR_BINARY_BLOB_HERE";
var restMsg = new XMLHttpRequest();
restMsg.open("post", "https://YOUR_INSTANCE.service-now.com/api/now/attachment/file?table_name=" +"YOUR_TABLE_NAME" +
"&table_sys_id=" +
"YOUR_TABLE_SYS_ID" +
"&file_name=" +
"YOUR_FILE_NAME");
restMsg.setRequestHeader('Accept', 'application/json');
restMsg.setRequestHeader('Authorization', 'Basic ' + btoa('USERNAME' + ':' + 'PASSWORD'));
//You can optionally specify another header for Content-Type and Content-LengthrestMsg.onreadystatechange = function() {
//The inline anon function inherits the state of the XMLHttpRequest object; hence 'this.<readyState/DONE>'.
if (this.readyState == this.DONE) {document.getElementById("response").innerHTML = this.status + this.response;
}};
restMsg.send(restRequestBody);
client.send(requestBody);
Sending this, will attach whatever file's binary data you have in the requestBody variable. There are a multitude of ways to get a file as a binary blob or string. Here's a fairly comprehensive article, and here's a StackOverflow post with two good solutions if you need them.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-29-2017 12:07 AM
Hi Timothy Woodruff,,
Thanks for your reply.
I am using helsinki version of service now and trying to attach a file with an incident using service api like jsonv2/table api.
Thanks,
Ramesh Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-29-2017 07:35 PM
My post described how to do that. Was there something I missed?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2017 08:44 AM