Attachment API Invalid file type issue

bota
Giga Contributor

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:bota_0-1709545354220.png
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

Kris Moncada
Tera Guru

Hi @bota ,

 

Did you ever get this resolved? I'm running into a similar issue; but my code is server-side.

Hi @Kris Moncada ,

 

Unfortunately I was not able to resolve this issue.