Jump to content

Upload images via the developer API with node.js

Recommended Posts

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 ? 

Link to comment
  • Replies 0
  • Views 298
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment


×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.