- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2025 09:51 AM
Dear Team,
I am using custom application, from the Update Business Rule I am trying to send attachment to another ServiceNow instance but I am getting this error :
{"error":{"message":"Invalid file type: application/json","detail":null},"status":"failure"}
Here is my BR code, Experts please help how can i fix this issue 😞
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2025 10:34 PM
I am able to send attachment now.
On the Rest Message Send Attachment Endpoint I have to add : https://instance.service-now.com/api/now/attachment/file?table_name=${table_name}&table_sys_id=${tab...
This did the magic!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2025 10:02 AM
Hi @mr_zia ,
The error Invalid file type: application/json indicates that the receiving ServiceNow instance is expecting a specific file type, but the request is being sent with a Content-Type of application/json. This is likely because the Content-Type header is being set incorrectly or the receiving endpoint does not accept JSON for file uploads.
Update your code as mentioned below
var qry = 'table_name=incident^u_sent_flag=false^table_sys_id=' + current.sys_id;
var att = new GlideRecord("sys_attachment");
att.addEncodedQuery(qry);
att.query();
while (att.next()) {
try {
var r = new sn_ws.RESTMessageV2('x_mea_inte_Integration', 'Send Attachment');
r.setStringParameterNoEscape('table_sys_id', '611b0822fbb392103bf0f471beefdc06'); // sys_id hard coded for testing.
r.setStringParameterNoEscape('table_name', 'incident');
r.setStringParameterNoEscape('file_name', att.file_name);
// Set headers correctly
r.setRequestHeader("Accept", "application/json"); // Accept header for response
r.setRequestHeader("Content-Type", att.content_type); // Content-Type for the attachment
// Attach the file content to the request body
r.setRequestBodyFromAttachment(att.sys_id);
// Execute the request
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.info("Attachment Update Response Body : " + responseBody);
gs.info("Attachment update status : " + httpStatus);
} catch (ex) {
var message = ex.message;
gs.error("Error sending attachment: " + message);
}
}
Please consider marking my reply as Helpful and/or Accept Solution, if applicable.
Regards,
Satya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2025 10:28 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2025 10:07 AM
Hi @mr_zia ,
Check the glide.attachment.extensions system property on the target instance the type of file extension your are sending is added.
Try using multi part as content type
r.setRequestHeader("Content-Type", "multipart/form-data");.
If my response helped, please mark it as the accepted solution ✅ and give a thumbs up👍.
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2025 10:53 AM
Hi Anand,
That's a very good point because every time I get invalid file type.
I dont see glide.attachment.extensions system property on Target instance, but on my instance we have this property,
On the Target Instance there 3609 records in system property out of then 99 are secured that I am not able to view, I will ask the target instance developer tomorrow.
Is there a chance glide.attachment.extensions record not there on target instance that could cause the error invalid file type?