The code I have that’s causing this is
new_order = shopify.Order.create(json.dumps({'order': { "email": "[email protected]", "fulfillment_status": "fulfilled", "line_items": [{'message': "words go here"}]}}))
I tried without the json.dumps and got the response that it was an unhashable type. also tried this from some reasearch
data = dict()
data['order']= { "email": "[email protected]", "fulfillment_status": "fulfilled", "line_items": [{'message': "words go here"}]}
print(data['order'])
new_order = shopify.Order.create(json.dumps(data))
What can I do to properly send in a simple order like in https://help.shopify.com/api/reference/order#create
C:Python27python.exe C:/Users/Kris/Desktop/moon_story/story_app.py
Traceback (most recent call last):
File "C:/Users/Kris/Desktop/moon_story/story_app.py", line 41, in <module>
{'fulfillment_status': 'fulfilled', 'email': '[email protected]', 'line_items': [{'message': 'words go here'}]}
get_story(1520)
File "C:/Users/Kris/Desktop/moon_story/story_app.py", line 29, in get_story
new_order = shopify.Order.create(json.dumps(data))
File "C:Python27libsite-packagespyactiveresourceactiveresource.py", line 448, in create
resource = cls(attributes)
File "C:Python27libsite-packagesshopifybase.py", line 126, in __init__
prefix_options, attributes = self.__class__._split_options(attributes)
File "C:Python27libsite-packagespyactiveresourceactiveresource.py", line 465, in _split_options
for key, value in six.iteritems(options):
File "C:Python27libsite-packagessix.py", line 599, in iteritems
return d.iteritems(**kw)
AttributeError: 'str' object has no attribute 'iteritems'
2
Answers
Comparing with help.shopify.com/api/reference there are the following differences:
The Endpoint have to be
/admin/orders.json
Why do you use
/admin
?The Main Key in the JSON Dict have to be
order
.Why don’t you use this, for example:
Use:
After some digging, I was able to get this working. You shouldn’t need to do anything special with the argument passed to
create
. The following works for me:It’s worth noting that this Python library relies on another Shopify created library called pyactiveresource. That library provides the underlying
create
method, which calls thesave
method.The save method has the following notes about responses:
I was continually getting a
False
response. This helped me understand which fields were actually required by looking at theerrors
attribute, so I figured it might be helpful here.