Fulfilments of orders using Python API and 2023-01

Can someone help me find out what am I missing in this Python code. It works fine with 2022-04 API version. Here is the error message: urllib.error.HTTPError: HTTP Error 404: Not Found

import shopify

API_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
API_SECRET = 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'
TOKEN = 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz'

shopify.Session.setup(api_key=API_KEY, secret=API_SECRET)

shop_url = "mysite.myshopify.com"
api_version = '2023-01'

session = shopify.Session(shop_url, api_version, TOKEN)
shopify.ShopifyResource.activate_session(session)

#unfulfilled orders
new_orders = shopify.Order.find()

for order in new_orders:
    fo = shopify.FulfillmentOrders.find(order_id=order.id)[0]
    location = fo.assigned_location_id
    fulfillable_quantity = fo.line_items[0].fulfillable_quantity
    
    fulfillment = shopify.Fulfillment({
            'order_id':fo.order_id,
           })

    fulfillment.location_id = location
    fulfillment.notify_customer = False
    fulfillment.message = 'The package has been shipped this morning'

    fulfillment.tracking_info = {
        "number": "11111111",
        "url": "https://mysite.myshopify.com",
        "company": "mycompany"
    };
    fulfillment.line_items_by_fulfillment_order = [
      {
        "fulfillment_order_id": fo.id,
        "fulfillment_order_line_items": [
          {
            "id": fo.line_items[0].id,
            "quantity": fulfillable_quantity
          }
        ]
      }
    ]
    fulfillment.save()                 
shopify.ShopifyResource.clear_session()

It looks like there is an issue with the shopify_python_api, which returns incorrect url when creating fulfillments ( shopify_python_api/issues/634 ). Hopefully an updated version can be released soon.

The order_id is also not a valid parameter, and the following line should be removed from the code above.

'order_id':fo.order_id

I hope this can help someone.

I’m trying to use your code as an example for my fulfillment. In 2023-01 and 2023-04 I am getting

urllib.error.HTTPError: HTTP Error 406: Not Acceptable

I’m curious if you have having any success with your processing. Thanks in advance.

I gave up on the python ShopifyAPI library and just did a post of the json. Shopify line item fulfillment example python code