attachmentAPI
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-30-2019 05:17 AM
Hello Can someone point out where am i going wrong
i need to pass an attachment from one Service now system to another gone through other link related to this but could not find anything good
here is the code i am using
(function sampleRESTMessageV2() {
try {
var user = <username>;
var password = <password>;
var sid = current.sys_id;
var filename = current.file_name;
var filetype = current.content_type;
//var tablename = current.table_name;
var r = new sn_ws.RESTMessageV2();
r.setEndpoint('<instance name>/api/now/attachment/file');
r.setHttpMethod('POST');
r.setBasicAuth(user,password);
r.setStringParameterNoEscape('table_name','incident');
r.setStringParameterNoEscape('table_sys_id',<incident sys_id>);
r.setStringParameterNoEscape('file_name',filename);
r.setStringParameterNoEscape('content-Type',filetype);
r.setRequestBodyFromAttachment(sid);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
}
catch (ex) {
var message = ex.getMessage();
gs.log('>>>>>message is >>> ' +message,'rajesh');
}
})();
I am getting response of 400
response body is :{"error":{"message":"Missing parameter: table_name","detail":null},"status":"failure"}
note sure where am i going wrong. I am passing table name, but not sure what needs to be details. I am passing most of the thing in attachment.
Regards
Rajesh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-30-2019 05:37 AM
try now.
(function sampleRESTMessageV2() {
try {
var user = <username>;
var password = <password>;
var sid = current.sys_id;
var filename = current.file_name;
var filetype = current.content_type;
//var tablename = current.table_name;
var r = new sn_ws.RESTMessageV2();
r.setEndpoint('<instance name>/api/now/attachment/file');
r.setHttpMethod('POST');
r.setBasicAuth(user,password);
r.setQueryParameter('table_name','incident');
r.setQueryParameter('table_sys_id',<incident sys_id>);
r.setQueryParameter('file_name',filename);
r.setRequestHeader('content-Type',filetype);
r.setRequestHeader("Accept", "application/json");
r.setRequestBodyFromAttachment(sid);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
}
catch (ex) {
var message = ex.getMessage();
gs.log('>>>>>message is >>> ' +message,'rajesh');
}
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-30-2019 05:47 AM
Sorry,
It still the same
have tried all combination i could think of this would not pass from servicenow,
but when i am passign through postman using binary it works as a charm.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-30-2019 05:55 AM
have you tried to convert those file into payload base64 and then passed it ?
adding one thread here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-30-2019 07:08 AM
that does not work either.
what i understand is system is not able to find the location , seems like i have to pass it with binary location.
as in example of curl system. --data-binary "@<location of the file on file system>"
I am not good with curl.
any idea how i can pass the value in url
curl <instance name>/api/now/attachment/file?table_name=incident&table_sys_id=<sysid>&file_name=<attachment name>"
if any one has done this using javascript please do share