Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Advanced Search
  • 0

Uploading Product Photo via API



Hi! I'm trying to programmatically upload photos to my products (https://developers.squarespace.com/commerce-apis/upload-product-image).

CURL Requests via Insomnia will work, but I cannot for the life of me get uploads via Python working. 

My code (generated from a working Insomnia request):

url = "https://api.squarespace.com/1.0/commerce/products/MY_PRODUCT_ID/images"
payload = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"MY_FILE_NAME.jpg\"\r\nContent-Type: image/jpeg\r\n\r\n\r\n-----011000010111000001101001--\r\n"
headers = {
    "Authorization": "Bearer MY_TOKEN",
    "User-Agent": "MY_USER_AGENT",
    "Content-Type": "multipart/form-data; boundary=---011000010111000001101001"
response = requests.post(url, data=payload, headers=headers)

I keep hitting this error:

"The provided file could not be read as an image."

Has anyone done this before? What am I missing? If anyone has code examples from any language I'm happy to reverse engineer!

Edited by ksho
clarifying some words
Link to comment
  • Answers 2
  • Created
  • Last Reply

Top Posters For This Question

Top Posters For This Question

2 answers to this question

Recommended Posts

  • 0

Hello @ksho,

Thanks for posting your question!

This example currently works for me, though I am not exactly sure the syntax in your example is correct:

import requests

url = "https://api.squarespace.com/1.0/commerce/products/<product id>/images"

  ('file',('<filename>',open('<path to image>','rb'),'image/jpeg'))
headers = {
  'Authorization': 'Bearer <api key>',
  'User-Agent': '<your user-agent>'

response = requests.request("POST", url, headers=headers, files=files)


Also, check that your images meets the platform requirements

Let me know if this resolves the issue!

Link to comment

Create an account or sign in to comment

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

  • Create New...