Attachment API Invalid file type issue
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2024 04:48 AM
Hello,
I am trying to attach excel file using attachment API and i am getting
Invalid file type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet error. I only get this error when trying to do this using a third-party tool, that requires me to write the payload in js. And only when i am trying to send excel files i tried to upload pdf the same way and it works. Here's my code:
===============================================================
let options = {
method: 'POST',
url: 'attachment/file?table_name=my_table&table_sys_id=' + sys_id + '&file_name=' + filename,
responseType: 'json',
resolveBodyOnly: true,
metadataType: irpa_core.enums.request.metadataType.formData,
headers: {
'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'Accept': '*/*'
},
body: content
};
return options;
===============================================================
I don't have any problem calling it via thunder client with the same payload:
Here's the CURL that works for the excel file:
curl -X POST \
'https://myinstance.service-now.com/api/now/attachment/file?table_name=mytable&table_sys_id=mysysid&file_name=myfilename' \
--header 'Accept: */*' \
--header 'Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' \
--header 'Authorization: Basic ' \
--data-binary '@c:\myfile.xlsx'
Any idea why it works with this CURL and doesn't work with the js code above?
Thank you!
Bota
2 REPLIES 2
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2024 07:37 AM
Hi @bota ,
Did you ever get this resolved? I'm running into a similar issue; but my code is server-side.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2024 06:40 AM