Sending a POST request with Flow Designer Action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2022 09:41 PM
Hello,
Sending a POST request(which has image upload) through Action in Flow Designer, what are the steps to upload images for POST request in Action and to test? Is there any way to do it? Any reference or videos are helpful.
Thanks in advance.
- Labels:
-
Integrations

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2022 08:47 PM
A POST will upload the file on the server that the script is running to ServiceNow's sys_attachment table.
Flow Designer runs on a ServiceNow server. So, doing a POST using Flow Designer will imply the image to be posted is already on ServiceNow server. If so, it would be faster to just copy the file instead of using a POST API.
To POST an image file that resides on the local computer to ServiceNow, it's necessary to execute the POST script on the local computer instead from Flow Designer.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2022 10:20 PM
My bad on the previous answer. Flow Designer can be used to send attachment from one instance to another.
Instead of REST step, I usually just use Script step. Just need to page code generated by REST API Explorer.
Example:
Script:
var table_name = inputs.from_table_name;
var table_sys_id = inputs.from_table_sys_id;
var instanceName = '<to_instance_name>';
var user = '<to_user_name>';
var password = '<to_password>';
var insertTableName = inputs.to_table_name;
var insertTableSysId = inputs.to_table_sys_id;
copyAttachments();
function copyAttachments() {
var att = new GlideRecord('sys_attachment');
att.addQuery('table_name', table_name);
att.addQuery('table_sys_id', table_sys_id);
att.query();
while (att.next()) {
gs.info(att.sys_id);
postAttachment(att);
}
}
function postAttachment(att) {
var request = new sn_ws.RESTMessageV2();
request.setHttpMethod('post');
request.setEndpoint("https://" + instanceName + ".service-now.com/api/now/attachment/file");
request.setQueryParameter("table_name", insertTableName); // attach to table name
request.setQueryParameter("table_sys_id", insertTableSysId); // attach to table record's sys_id
request.setQueryParameter("file_name", att.file_name);
request.setRequestHeader("Content-Type", att.content_type);
request.setRequestHeader("Accept", "application/json");
request.setRequestBodyFromAttachment(att.sys_id); // file to attach
request.setBasicAuth(user, password);
request.setRequestHeader("Accept", "application/json");
var response = request.execute();
var httpResponseStatus = response.getStatusCode();
gs.info("http response status_code: " + httpResponseStatus);
}