Add file to Notes via REST API using NodeJS

I can successfully create the note.

I now need to upload the file and then link to the note.

Which I think I can do with this endpoint:

"/rest/v11_20/Notes/5f95bbe8-cd49-11ee-b015-fa163ec72422/file/filename"

I'm POSTing a file using FormData from my app and handling this on my NodeJS server.

Here I use axios to call the Endpoint above.

However, whatever format I pass the file in, I get either a 400 or a 422 returned from the Sugar API.

I've tried several things:

  • setting. removing / changing content-type 
  • setting / removing content disposition
  •  pass file as raw File, FormData, Buffer

Fullscreen
1
2
3
4
5
6
7
8
9
// this adds in basepath and sets api version
const fileUrl = getFileUrl(config, noteId)
const fileResponse = await axios.post(fileUrl, file, {
headers: {
'OAuth-Token': accessToken,
},
});
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

 
Has anybody had success doing this? Can you share your code?
Thanks