Having trouble with POST to products.json

Highlighted
New Member
1 0 0

I am trying to post to products.json to create a product on my shopify store. I have been following the api references, and am literally copying the api reference examples word for word.

I use this as my code in python:

import requests

payload = '''{ "product": { "title": "Burton Custom Freestyle 151", "body_html": "<strong>Good snowboard!</strong>", "vendor": "Burton", "product_type": "Snowboard", "tags": [ "Barnes & Noble", "John's Fav" ] } } ''' resp = requests.post(f'{shop_url}/admin/api/2020-04/products.json', data=payload) print(resp, resp.text)

and when running this, where shop_url is:

shop_url = "https://%s:%s@syntoolsshop.myshopify.com" % (APIKEY, PASSWORD) 

 I get this as my returned print statement:

<Response [400]> {"errors":{"product":"Required parameter missing or invalid"}}

 

I am literally following the docs word for word, I have 0 idea why this is happening, any ideas?

0 Likes
Highlighted
Shopify Partner
520 38 109

Check that the body is being passed into your API request as true JSON. Which is what the API endpoint is expecting. See this link for details --> https://pynative.com/python-post-json-using-requests-library/

1 Like
Highlighted
Shopify Partner
520 38 109

Where did you see variant options being defined in his sample?

0 Likes