I'm trying to upload images to my website through the commerce API with node.js.
Here is my code so far. FormData and fetch have been imported.
const form = new FormData();
form.append("file", fs.readFileSync("image.png"));
const send_img = await fetch(
"https://api.squarespace.com/1.0/commerce/products/" + image_id + "/images",
{
method: "POST",
headers: {
Authorization: "Bearer " + process.env.SQUARESPACE_API_KEY,
"User-Agent": "MY-USER-AGENT",
"Content-Type": "multipart/form-data",
},
body: form,
}
);
I keep getting this error.
{
type: 'INVALID_REQUEST_ERROR',
subtype: null,
message: "Expected exactly one file part named 'file', but found none.",
details: null,
contextId: 'EPOYCREESOOSLEEWRAWX'
}
Can someone help me resolve this error ?