skip to Main Content

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


  1. Comment: … get an order(None) as response. … Any thoughts?

    Comparing with help.shopify.com/api/reference there are the following differences:

    1. The Endpoint have to be /admin/orders.json

      Why do you use /admin?

    2. The Main Key in the JSON Dict have to be order.

      Why don’t you use this, for example:

      {
        "order": {
          "email": "[email protected]",
          "fulfillment_status": "fulfilled",
          "line_items": [
            {
              "variant_id": 447654529,
              "quantity": 1
            }
          ]
        }
      }
      

    Use:

    new_order = shopify.Order.create(data['order'])
    
    Login or Signup to reply.
  2. 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:

    shop_url = "https://%s:%s@%s.myshopify.com/admin" % (shopify_key, shopify_pass, shopify_store_name)
    shopify.ShopifyResource.set_site(shop_url)
    
    order_data = {
            "email": "[email protected]",
            "fulfillment_status": "fulfilled",
            "line_items": [
                { 
                    "title": "ITEM TITLE",
                    "variant_id": 7214792579,
                    "quantity": 1,
                    "price": 895
                }
            ]
        }
    
    shopify.Order.create(order_data)
    

    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 the save method.

    The save method has the following notes about responses:

    Args:
      None
    Returns:
      True on success, False on ResourceInvalid errors (sets the errors
      attribute if an <errors> object is returned by the server).
    Raises:
      connection.Error: On any communications problems.
    

    I was continually getting a False response. This helped me understand which fields were actually required by looking at the errors attribute, so I figured it might be helpful here.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search