How to configure the tracking infos using the Shopify FulfillmentOrder API?

I am using the shopify plus and going to migrate the shopify fulfillment api from 2022-4 to 2023-4.
I know that I should migrate from Shopify Fulfillment api to FulfillmentOrder api until June 30, 2023.
I am using the Shopify gem in my app (Ruby) and Fulfillment api is used like this way.

How can I configure tracking info for fulfillment using the FulfillmentOrder API?

fulfillment = ShopifyAPI::Fulfillment.new(order_data)
fulfillment.tracking_numbers = [vendor_order.tracking_numbers].flatten
fulfillment.tracking_urls = tracking_urls
fulfillment.tracking_company = shipping_company
fulfillment.save

Hello,

From the docs

fulfillment.tracking_info = {
“number” => “MS1562678”,
“url” => “https://www.my-shipping-company.com?tracking_number=MS1562678
}

Can read here Fulfillment (shopify.dev)

Thanks for the reply.
But in 2023-4 api version, the endpoint /orders/{order_id}/fulfillments.json is already removed so I can’t save the fulfillment using the order_id.
It recommends to use the FulfillmentOrder instead of Fulfillment Resource.

https://shopify.dev/api/release-notes/2022-07#fulfillment-endpoints-removed-from-the-rest-admin-api
My question is how to use that?

order_data = {
      "order_id": '231643452346',
      "location_id": '323432341',
      "fulfillment": {
        "message": 'The package was shipped.',
        "notify_customer": true,
        "line_items_by_fulfillment_order": [
          {
            "fulfillment_order_id": '231643452346',
            "fulfillment_order_line_items": []
          }
        ]
      }
    }

fulfillment = ShopifyAPI::Fulfillment.new(order_data)
fulfillment.tracking_info = {
   "number" => "MS1562678",
   "url" => "https://www.my-shipping-company.com?tracking_number=MS1562678"
}
fulfillment.save
fulfillment = ShopifyAPI::Fulfillment.new(order_data)

The fulfillment class uses

/admin/api/2023-04/fulfillments.json

which is not one of the urls being deprecated.

Now you will likely need to use the order id to fetch all the fulfillmentOrders

fulillment_orders = ShopifyAPI::FulfillmentOrder.all(order_id: order_id)

fulfillment = ShopifyAPI::Fulfillment.new(session: test_session)

# This would fulfill all but you can filter out the ones you want
fulfillment.line_items_by_fulfillment_order = fulfillment_orders.map {|fo| { 'fulfillment_order_id' => fo.id } }

fulfillment.tracking_info = {
  "number" => "MS1562678",
  "url" => "https://www.my-shipping-company.com?tracking_number=MS1562678"
}
fulfillment.save!

you might also need an extra step if you only want to fulfill certain items within a fulfillment order

When I run

fulillment_orders = ShopifyAPI::FulfillmentOrder.all(order_id: order_id)
.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/shopify_api-9.5.1/lib/shopify_api/resources/fulfillment_order.rb:16:in `find': 'order_id' is required (ShopifyAPI::ValidationException)

This error throws.
May I know the reason. The order_id exists in orders.

fulillment_orders = ShopifyAPI::FulfillmentOrder.all(order_id: '4993015283893')

I can see you are using shopify_api-9.5.1

You can see here as maybe need to adapt

Shopify/shopify-api-ruby: ShopifyAPI is a lightweight gem for accessing the Shopify admin REST and GraphQL web services. (github.com)

yes, almost done.
But I have one question more.

fulfillment.line_items_by_fulfillment_order = [
      {
        "fulfillment_order_id": vendor_order.order.shopify_id,
        "fulfillment_order_line_items": fulfillment_order_line_items
      }
    ]

I want to add the fulfillment_order_line_items also to line_items_by_fulfillment_order.

fulfillment.line_items_by_fulfillment_order = fulfillment_orders.map {|fo| { 'fulfillment_order_id' => fo.id } }

This code is only for adding the fulfillment_order_id.
In this case how can I do that?

As the references, I am adding the source_line_item_id and quantity only to fulfillment_order_line_items.

fulfillment_order_line_items = line_items.map do |item|
      { "id": item.source_line_item_id, "quantity": item.quantity }
    end

You need to select the items you want to fulfill and pass them as an array

fulfillment.line_items_by_fulfillment_order = [
  {
    "fulfillment_order_id" => 1046000849,
    "fulfillment_order_line_items" => [
      {
        "id" => 1058737608,
        "quantity" => 1
      }
    ]
  }
]

Is there any way to get this using the fulfillment_orders?

fulillment_orders = ShopifyAPI::FulfillmentOrder.all(order_id: '4993015283893')