JavaScript - How to send PDF file to POST /now/attachment/upload
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-18-2022 09:28 AM
I'm trying to attach a PDF file to our tickets via the /now/attachment/upload API.
Having issues figuring out the correct syntax to do this with JavaScript, I have tried the below solution with axios
This returns a 400 - Bad Request error. I'm looking for a code example of using this API with JavaScript
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-18-2022 10:35 PM
Hi,
In postman or curl your request would look like:
For Axios, you need to use FormData - Web APIs | MDN (mozilla.org)
var bodyFormData = new FormData();
bodyFormData.append('table_name', 'incident');
bodyFormData.append('table_sys_id', '46e2fee9a9fe19810049b49dee0daf58');
bodyFormData.append('uploadFile', 'file_here');
axios({
method: "post",
url: "myurl",
data: bodyFormData,
headers: { "Content-Type": "multipart/form-data" },
})
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-19-2022 09:30 AM
Hi Kieran, thanks for the reply.
What are you putting in the 'file_here' section on this line?
bodyFormData.append('uploadFile', 'file_here');
Lets say its a file on the file system

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-19-2022 05:09 PM
I've never done this, I'm only going off of tacit knowledge and my understanding of the APIs.
If you're server side, you can do the file path, if you're client side it would need to be an input field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-11-2023 11:40 AM
Hi Anthony,
have you fix this issue, if yes
am facing same issue could you please help me.
thank you.