Attachment Move Integration
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2024 03:09 AM - edited 06-14-2024 03:13 AM
Hello Experts,
I am trying to move an attachment from ServiceNow to Aha.
The Aha application requires the request body to be in the following format:
------------XnJLe9ZIbbGUYtzPQJ16u1
content-disposition: form-data; name="attachment[data]"; filename="sample_plain_text.txt"
content-type: text/plain
content-length: 27
[uploaded data]
------------XnJLe9ZIbbGUYtzPQJ16u1--
I have the following background script, but it is not working and I am receiving a "bad request" error. Could you please guide me on this?
Thank you.
Background script;
// Fetch the attachment from ServiceNow
var attachmentSysId = '53c4b8bc83fa4210ae8dc4a6feaad3ab';
var attachmentGr = new GlideRecord('sys_attachment');
if (attachmentGr.get(attachmentSysId)) {
var attachment = new GlideSysAttachment();
var attachmentStream = attachment.getBytes(attachmentGr);
var base64Content = GlideStringUtil.base64Encode(attachmentStream);
gs.print(base64Content);
// Prepare the payload for Aha!
var payload = {
"attachment": {
"file_name": attachmentGr.file_name,
"content": base64Content
}
};
// Send the attachment to Aha!
var request = new sn_ws.RESTMessageV2('Aha Integrations', 'Add Attchment on Comments');
request.setRequestBody(JSON.stringify(payload));
var response = request.execute();
var responseBody = response.getBody();
gs.info('Aha! response: ' + responseBody);
} else {
gs.error('Attachment not found');
}
Aha Docs Link for reference:
https://www.aha.io/api/resources/attachments/create_an_attachment_on_a_comment
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2024 05:23 PM
Since it's a bad request, it may help to define the request headers like in the following example:
var sm = new sn_ws.RESTMessageV2("<REST_message_record>","get"); //Might throw exception if message doesn't exist or not visible due to scope.
sm.setRequestHeader("Accept","Application/json");