Creating a fulfillment with Shopify Python SDK

zainlks
New Member
2 0 0

When I try and create a fulfillment through the Shopify Python SDK, the fulfillment is not created, and I am seeing a None response, here is what I'm trying:

fulfillment = shopify.Fulfillment({'order_id':order.id})

fulfillment.location_id = loc_id
fulfillment.line_items = [{ "id": 12345678 }]
fulfillment.notify_customer = False
fulfillment.save()
print(fulfillment)

Printing fulfillment outputs Fulfillment(None). This seems to work for some stores and not others, any advice?

P.S. I have also confirmed the order id, line item id and location id are not none and valid.

Replies 4 (4)
zainlks
New Member
2 0 0

As a follow up, This is being done through an app that merchants install. Here are the scopes we are using:

'read_all_orders', 'read_orders', 'write_orders',
'read_products', 'write_products',
'read_locations',
'read_script_tags', 'write_script_tags',
'write_inventory'

syf_
Shopify Staff
92 20 15

@zainlks could you please provide a request id (found in the response header) of a call that fails, and we'd be able to check the logs for what might have gone wrong.

Thanks,
Seth.

syf_ | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Vinh
Excursionist
11 0 2

You have the write_order scope, so the permission is good.

I would clean up your code a bit and rewrite it like this. fulfillment.line_items = [{"id": 12345678}] is probably not working. The object shopify.Fulfillment expects a (list of) line_item object there, not just a list with an ID. In this case, I derive it from the order. I also derive the location_id from the location object. Depending on how many locations you have, change the 0 in shopify.Location.find()[0].

hth

 

 

order = shopify.Order.find(1234567890)
location = shopify.Location.find()[0]
fulfillment = shopify.Fulfillment({'order_id': order.id,
                                   'location_id': location.id,
                                   'line_items': order.line_items,
                                   'notify_customer': False})
print(fulfillment)

 

 

 

Vinh
Excursionist
11 0 2

If you really have to use line_item_id, then you can try to replace order.line_items with shopify.LineItem(1234567)