0
votes

I have read through the Shopify API documentation for how to insert an image to Shopify from here: https://shopify.dev/docs/admin-api/rest/reference/products/product-image

I have the following code, which can successfully connect to Shopify and retrieve images associated with a product:

import requests

# Connect to Shopify
shop_url = "https://%s:%[email protected]/admin/api/%s/products/5161320611973/images.json" % (API_KEY, PASSWORD, API_VERSION)

# Get data
data = requests.get(shop_url)

This works successfully, Now I would like to upload a new image to a product. This is the code I am using:

# Create image data
imgdata = {
  "image": {
    "src": "https://pkmncards.com/wp-content/uploads/en_US-CP-079-charizard_v.jpg"
  }
}

# POST image data to Shopify
x = requests.post(shop_url, data = imgdata)

This gives the following result:

<Response [400]>
{'errors': {'image': 'expected String to be a Hash'}}

Does anyone have a suggestion as to what mistake I may have made?

1

1 Answers

0
votes

Using json instead of data in the requests should do the trick:

# POST image data to Shopify
x = requests.post(shop_url, json = imgdata)