how to modify Shopify product json file with Shopify Python API

how to modify Shopify product json file with Shopify Python API

federikowsky
Visitor
3 0 1

I'm trying to update product json field with python, but something goes wrong. My idea was to take the product json file and change the fields that interested me without manually creating it for each product but got error 400 with put request. Also searching on internet I didn't find solution. here is my code:

 

 

 

import requests
import pprint


r = requests.get('https://shopify_api@myshop.myshopify.com/admin/api/2021-10/products.json')

file = r.json()
pprint.pprint(file)
print('\n\n')

file['products'][0]['variants'][0]['price'] = '30'

pprint.pprint(file)
print('\n\n')

id_product = file['products'][0]['id']
print(id_products)

headers = {"Accept": "application/json", "Content-Type": "application/json"}

url = 'https://shopify_api@myshop.myshopify.com/admin/products/' + str(id_products) + '.json'
print(url,'\n\n')

r = requests.put(url, json=file, headers=headers)
# r = requests.put(url, data=file, headers=headers)

print(r)

r = requests.get(url)
pprint.pprint(r.json())

 

 

 

 

someone know how can I fix it?

 
Replies 0 (0)