Covers all questions related to inventory management, order fulfillment, and shipping.
know how to solve it?
Hi DjSchutz,
Are you using a library to make API calls to Shopify with python?
Liam | Developer Advocate @ Shopify
- Was my reply helpful? Click Like to let me 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
Only requests and this class:
class ShopifyInterface:
def __init__(self, shop_key):
self.shop_url = #url here
self.access_key = shop_key
self.api_version = '2023-10'
self.base_url = f"{api_ley}:{shop_key}@{self.shop_url}/admin/api/{self.api_version}/"
self.auth_headers = {
"Content-Type": "application/json",
"X-Shopify-Access-Token": self.access_key
}
self.pagination_wait_time = 0.33 #Prevent rate limiting
##### function to add new products and update the price of existing products ################
@anvil.server.callable
def update_product_prices(product_id, new_price):
shop_key = anvil.secrets.get_secret('shopify_admin_key')
shop = ShopifyInterface(shop_key)
# Assuming you want to update a specific variant
variant_id = 47957229371665
payload = {
"variants": [{
"id": variant_id, # Use the correct field name for variant ID
"price": new_price # Use the new_price parameter
}]
}
headers = {"Content-Type": "application/json", **shop.auth_headers}
endpoint = f"{shop.base_url}products/{product_id}" # Fix the typo in the endpoint URL
response = requests.put(endpoint, json=payload, headers=headers)
if response.ok:
print(f"Price updated successfully for product {product_id}")
print(response.text)
print(response.status_code)
else:
print(f"Failed to update price for product {product_id}: {response.text}")
print(response.status_code)
UPDATE: I'm now getting a 200 status code but it's not actually updating
I believe this is something related to Python not working correctly with Shopify - I'm investigating something similar here: https://community.shopify.com/c/authentication-and-access/update-product-variant-issue-with-admin-ap...
Liam | Developer Advocate @ Shopify
- Was my reply helpful? Click Like to let me 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