I cannot upload new images on new products via REST API. Error 404

Solved
Coludus
Tourist
8 0 2

I tried to upload images as URL on new products with REST API, but the error reads "404 Not Found".

Although I can upload images on products existing images, I cannot do first image on them.

I am using Python and REST API, and writing code like the below

 

import shopify
import requests

SHOP_URL = "https://example.myshopify.com"
API_SECRET ="password"
product = shopify.Product()
product_id = product.variants[0].id
endpoint = f'{SHOP_URL}/admin/api/2021-07/products/{product_id}.json'
headers = {
    "Content-Type": "application/json",
    "X-Shopify-Access-Token": API_SECRET,
}
src="https://example.com/jpg"

image  =  {
"product": {
    "images": [
      {"src": src}
    ]}
}

r = requests.put(endpoint, headers=headers, image)
print(r)

 

<Response [404]>

Please tell me why

Accepted Solution (1)

Accepted Solutions
Jayvin
Shopify Partner
284 42 85

This is an accepted solution.

Hi,

product_id = product.variants[0].id

Your product_id variable is wrong. Should be like this:

product_id = product.id;

View solution in original post

Replies 2 (2)
Jayvin
Shopify Partner
284 42 85

This is an accepted solution.

Hi,

product_id = product.variants[0].id

Your product_id variable is wrong. Should be like this:

product_id = product.id;
Coludus
Tourist
8 0 2

Thank you soo much!!

It worked well!

I appreciate it!