Fulfill orders with Python

Highlighted
Shopify Partner
2 0 0

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
Highlighted
Shopify Partner
1840 177 712

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 and Candy Cart or offer free gifts with Gift Box. All made with ❤️  and care by Digismoothie
0 Likes
Highlighted
Shopify Partner
2 0 0

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()

 

0 Likes
Highlighted
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