Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Re: PUT 200 but price not updated

Solved

PUT 200 but price not updated

swong94
Tourist
7 1 1

Hi, 

 

I've spent hours trying to figure out why requests isn't working for put. I'm posting here as i'm totally stuck.

I get 200OK but the response shows an unchanged product/variant/

Can I get help on this please?

 

My goal is to change price/sku according to the json provided.

 

X-Request-ID': '43a42d0f-75e0-4aee-b90c-fd5800e72940'

 

 

 

 

 

import requests


headers = {"X-Shopify-Access-Token": "{token}","Content-Type": "application/json"}

data={"product":{"id":8077722714417,"title":"Default Title","variants":[{"id":44193894662449,"price":"1200.00","sku":"kdkfjdskfd"}]}}

api_url = f"https://{website.com}/admin/api/2022-10/products/8077722714417.json"


res = requests.put(api_url,json=data, headers=headers,allow_redirects=True)
print(res)

print(res._content)

 

 

 

As you can see, below response is what i get and it doesn't show an updated price (expecting 1200.00 but got 120.00).

 

<Response [200]>

 

 

b'{"product":{"id":8077722714417,"title":"Default Title","body_html":"Description","vendor":"SanDisk","product_type":"Memory Card","created_at":"2022-12-08T18:27:34+11:00","handle":"sandisk-ultra-sdxc-sdunc-256gb-c10-uhs-i-150mb-s-r-4x6-10y","updated_at":"2022-12-08T23:39:57+11:00","published_at":"2022-12-08T18:27:34+11:00","template_suffix":null,"status":"active","published_scope":"web","tags":"Memory Card","admin_graphql_api_id":"gid:\\/\\/shopify\\/Product\\/8077722714417","variants":[{"id":44193894662449,"product_id":8077722714417,"title":"Default Title","price":"120.00","sku":"Updating the Product SKU","position":1,"inventory_policy":"deny","compare_at_price":null,"fulfillment_service":"manual","inventory_management":"shopify","option1":"Default Title","option2":null,"option3":null,"created_at":"2022-12-08T18:27:34+11:00","updated_at":"2022-12-08T23:39:57+11:00","taxable":true,"barcode":null,"grams":0,"image_id":null,"weight":0.0,"weight_unit":"kg","inventory_item_id":46241507606833,"inventory_quantity":100,"old_inventory_quantity":100,"requires_shipping":true,"admin_graphql_api_id":"gid:\\/\\/shopify\\/ProductVariant\\/44193894662449"}],"options":[{"id":10257447584049,"product_id":8077722714417,"name":"Title","position":1,"values":["Default Title"]}],"images":[],"image":null}}'

 

Accepted Solution (1)
swong94
Tourist
7 1 1

This is an accepted solution.

All good - fixed by using urllib3. Not sure why requests isn't working but maybe this will help someone that is stuck using requests.

View solution in original post

Replies 2 (2)

ShopifyDevSup
Shopify Staff
1453 238 524

Hey @swong94,

When testing on our end but were unable to replicate the behavior described, with either the product or product variant REST endpoints, as well as across multiple API versions.  

Would you be able to replicate this again, log and then share the following response headers: x-request-id and date (timestamp)

If possible, testing with an API client like Postman for debugging will also help rule out any potential app level configurations. The requested details are generic to share in thread here, and with examples we can take a look at logs on our end, share any findings, suggestions or next steps. 

Best!

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

swong94
Tourist
7 1 1

This is an accepted solution.

All good - fixed by using urllib3. Not sure why requests isn't working but maybe this will help someone that is stuck using requests.