Fulfill orders with Python

Dominik_Fischer
Shopify Partner
3 0 2

Hi!

I'm experiencing problems with fulfilling an order manually with Python. I already tried following a solution I found in another thread but it didn't work for me. 

The orders I want to process are not fulfilled (order.fulfillment_status = None / order.fulfillments = [ ])

order = shopify.Order.find(order_id)

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

fulfillment.tracking_company = 'DHL'
fulfillment.tracking_number = '12343'
fulfillment.tracking_url = 'some-tracking-url.com/12343'
fulfillment.notify_customer = True

fulfillment.save()

After running the script, fulfillment is an empty list [ ]. I wonder if I'm missing a way to "create" a fulfillment object..?

Your help is much appreciated.

0 Likes
KarlOffenberger
Shopify Partner
1866 184 828

Hi Dominik,

I am suspecting you are missing the location_id.

Apps are required to specify a location_id when creating fulfillments. For more information, see Managing fulfillments.

Hope this helps!

Liked this post? You might also like our fantastic upsell apps Candy Rack, Last Upsell post-purchase and Candy Cart or offer free gifts with Gift Box. All made with ❤️  and care by Digismoothie
0 Likes
Dominik_Fischer
Shopify Partner
3 0 2

Thanks a lot!

I guess it's obvious for most developers but I'l sum it up for other people with the same problem:

locations = dict()
for location in shopify.Location.find():
    locations[location.city] = locations[id]

#Choose location
city = YOUR_LOCATION #str

order = shopify.Order.find(ORDER_ID)

fulfillment = shopify.Fulfillment({
                  'order_id':order.id,
                  'line_items':order.line_items,
                  'location_id':locations[city]
                  })

fulfillment.tracking_company = 'DHL'
fulfillment.tracking_number = '12343'
fulfillment.tracking_url = 'some-tracking-url.com/12343'
fulfillment.notify_customer = True
fulfillment.save()

 

kopify-user-9
New Member
1 0 0

I was playing with this code. when fulfillment.save() is invoked, the order is fulfilled, closed and archived.

2 questions, some how related.

what if there are multipart orders fulfilled at different times? the documentation says that to have the id of the item that is fulfilled in line_items [line_item[0].id]

did that, still closes the order.

what if we want to fulfill the order but not close or archive it? is it possible with python sdk?

0 Likes
mikeschem
New Member
2 0 0

If I'm trying to act as a fulfillment service, how do I query for fulfillment orders?

0 Likes