Hello, I am having some issues updating products on the shopify API.
I am able to get, delete, and even loop over paginated API calls when pulling large amounts of data. But for some reason, I can’t get the products to update. Below is my code.
Thank you in advance!!!
def add_tag_to_product_by_id(id):
api_url = f'{url}products/{id}.json'
#https://(API_KEY):(TOKEN)@(SHOP_URL)/admin/api/2024-01/products/4620786335829.json
newTagData = {"product": {"id": id, "tags": "new_tagsss, newertags"} }
#{'product': {'id': 4620786335829, 'tags': 'new_tagsss, newertags'}}
r = requests.put(api_url, params= newTagData )
productsOBJ = r.json()
productsOBJ1 = json.dumps(productsOBJ,indent = 6)
print(productsOBJ1)
#The Printed response from the code above
{
"errors": {
"product": "expected String to be a Hash"
}
}
I feel like I have tried every variation possible with the put.request call. I look up the “expected String to be a Hash”
This link is to the shopify community answer to that issue above.
Shopify Community 2280911 - Solved
After reading this I then changed my code to this.
def add_tag_to_product_by_id(id):
api_url = f'{url}products/{id}.json'
newTagData = {"product": {"id": id, "tags": "new_tagsss, newertags"} }
print(type(newTagData))
#
The above code outputs this error which is almost comical.
```python
raise TypeError(f'the JSON object must be str, bytes or bytearray, '
TypeError: the JSON object must be str, bytes or bytearray, not dict
So the community says make it an object, and shopify says it wants a string. But Hashed!
How do I update a product with a requests.put()?
(PS. Why does the shopify documents not have any python related examples?)