Next order "in line"

Hey there,
I’d like to know if it is possible to retrieve the “Orders” list present for each product, via API in some manner.
Specifically, I’d like to know which orders are still backordered for a specific product, so that I may figure out which one is “next in line”, so to speak.

Are there any queries I can launch to achieve this?

Thanks!

Hello @craspini!

The best way to achieve this is to use a query like the following one and check the back-ordered quantity for the line item that contains that product in each order.

query{
  orders(sku:"string" fulfillment_status:"string" order_date_from:"ISODateTime" order_date_to:"ISODateTime"){
    complexity
    request_id
    data(first:10 sort:"order_date"){
      pageInfo{
        hasNextPage
        endCursor
      }
      edges{
        node{
          legacy_id
          order_date
          line_items(first:2){
            pageInfo{
              hasNextPage
              endCursor
            }
            edges{
              node{
                sku
                backorder_quantity
              }
            }
          }
        }
      }
    }
  }
}

As you can see:

  1. I filtered the orders by those that contain that particular SKU.
  2. I am also using the fulfillment_status filter to avoid fetching fulfilled orders, as I don’t need them, and they will consume credits. Suppose you have many other than the default ones; you will need to query each separately.
  3. order_date_from and order_date_to are there if you have many orders per day and you’d rather filter even more.
  4. Orders are sorted by order_date, which is the day the order was created, so you can compare which one needs to be attended to first.
  5. Line items only return SKU and backorder_quantity. You will need to check if SKU matches the SKU you are looking for and if its backorder quantity is more than 0.

I hope I was clear enough. If not, please let me know!

Have a great day!
TomasFD

Thank you, that is very clear!

One more question… what if we were to reverse the query?
Specifically, is it possible to launch a query for a specific order and see what position “in line” it is for each sku?

Hello @Csraspini!

If you mean like with a query to an order, find out how many unfulfilled orders with that SKU were created before, or something along those lines. Unfortunately, we have no way to do so.

I guess you could build something on your end using this query daily to build these “lists” on your end and use the Shipment Update Webhook to cross out those orders as they are fulfilled. That webhook will tell you which line items from which orders were shipped, that way, if the order is partially shipped, you can check which of the backordered items, in case it has more than one, were shipped.

Have a great day!
TomasFD

Thank you!

One more question… is it possible to filter the line_items node by sku? What fields can I sort by?

Hello @Csraspini!

Unfortunately, that node can’t be filtered by a specific SKU.

Are you looking into a particular field to sort by? I believe backorder quantity would be the most useful, but that is not a field you can sort by.

Kind regards,
TomasFD

Yes, backorder qty would have been good…

What I am currently doing is this:
checking to see what sku is backordered in a specific order (say order n. 123);
checking how many of that sku is backordered (say 10);
pulling up the most recent 10 orders (given that order is generally FIFO unless priority is specified);
checking how many orders there are before order n. 123.

It seems to be working pretty well, but the only issue is that if there is an order with high priority, the position will be off by one… not sure if there is a way around this with filters, but if not it’s a pretty good compromise!

Hello @Csraspini!

Currently, there is no way within the API. Can you filter them in your end when you consume the query?

Kind regards,
TomasFD