I am attempting to use the PUT Admin API for product variants located here:
https://shopify.dev/docs/api/admin-rest/2024-01/resources/product-variant#put-variants-variant-id
I am using a python client with the requests library (using requests directly is much smoother than trying to navigate the python client imo). This is not an import detail but one that informs the code:
To test the endpoint, I did a get request on a given variant, which returned appropriately (I have my headers and base url in a predefined object):
variant_id = 47772111503633
headers = {"Content-Type": "application/json", **shop.auth_headers}
endpoint = f"{shop.base_url}variants/{variant_id}.json"
response = requests.get(endpoint, headers=headers)
response.json()
{'variant': {'id': 47772111503633,
'product_id': 9061036785937,
'title': 'Default Title',
'price': '6.99',
'sku': '',
'position': 2,
'inventory_policy': 'deny',
'compare_at_price': None,
'fulfillment_service': 'manual',
'inventory_management': 'shopify',
'option1': 'Default Title',
'option2': None,
'option3': None,
'created_at': '2023-12-06T11:39:04-06:00',
'updated_at': '2023-12-06T11:39:04-06:00',
'taxable': True,
'barcode': '',
'grams': 113,
'image_id': None,
'weight': 0.25,
'weight_unit': 'lb',
'inventory_item_id': 49754018152721,
'inventory_quantity': 1,
'old_inventory_quantity': 1,
'requires_shipping': True,
'admin_graphql_api_id': 'gid://shopify/ProductVariant/47772111503633'}}
Now, when I go to place a PUT request to the same place, I am getting an issue:
variant_id = 47772111503633
payload = {
"variant": {
"id": variant_id,
"price": "7.99"
}
}
headers = {"Content-Type": "application/json", **shop.auth_headers}
endpoint = f"{shop.base_url}variants/{variant_id}.json"
response = requests.put(endpoint, json=payload, headers=headers)
I have tried every version of “id”, “variant_id”, dumping the json to a string, etc, and this continues to give me the same error. It seems that there is either be something I’m missing, or this specific end point has a bug. Can anyone please assist?



