Built something you're proud of? Tell the story. A quick G2 review of App Engine or Build Agent helps other developers see what's possible on ServiceNow. Share your experience.

Send attachment via rest message

Khanna Ji
Tera Guru

Hi, 

We are using VirusTotal for scanning virus. It has a APIs to scan attachments.

How can I sent an attachment file to this API from ServiceNow? Link to the API and details are shared below.

https://developers.virustotal.com/v2.0/reference#file-scan 

6 REPLIES 6

I want to send attachment from ServiceNow to third party not vise versa

Hi,

Below script does the same 

var target = new GlideRecord('sys_attachment');
target.addQuery('table_name', 'incident');
target.addQuery('table_sys_id', current.sys_id);
target.query();

while(target.next()) {
  var sa = new GlideSysAttachment();
  var binData = sa.getBytes(target);
  var base64Data = GlideStringUtil.base64Encode(binData);

  //Send Attachments
  var requestAttachment = new sn_ws.RESTMessageV2();
  requestAttachment.setEndpoint('https://XXXXX.service-now.com/api/now/import/u_attachment_staging_table');
  requestAttachment.setHttpMethod('POST');

  requestAttachment.setBasicAuth(user,password);
  requestAttachment.setRequestHeader("Accept","application/json");
  requestAttachment.setRequestHeader('Content-Type','application/json');

  var requestAttachmentJSONBody = createRequestBody("u_name", target.file_name + ":" + target.content_type);
  requestAttachmentJSONBody += addToRequestBody("u_ticket_number", 'incident:' + sysid);
  requestAttachmentJSONBody += addToRequestBody("u_attachment", base64Data);
  requestAttachmentJSONBody += closeRequestBody();

  requestAttachment.setRequestBody(requestAttachmentJSONBody);

  var responseAttachment = requestAttachment.execute();
}