Most efficient way to get number of items in a shipment?

I am are trying to find out how many items are tied to each shipping label for a shipment, this data is used for a task that is run daily.

If we add a query for shipment line items the complexity goes through the roof and our daily job gets IMMENSELY more complicated (We have to handle querying for more shipments, more shipment line items on each shipment IFF there’s more than the initial request amount, along with API credit limits and timeouts.

We do not need to know every product that was shipped, only how many items were shipped with each shipping label. Is there a more efficient way to go about this?

Our current query looks like this:

query{
  shipments(date_from: "yyyy-yy-yy", date_to: "xxxx-xx-xx"){
    complexity
    request_id
    data(first: 100){
      pageInfo{
        hasNextPage
        endCursor
      }
      edges {
				node {
					id
					created_date
					profile
					user_id
					warehouse_id
					shipped_off_shiphero
					order{
						rma_labels{
							shipment_id
						}
						returns{
							id
							status
							reason
						}
						account_id
						id
					}
					shipping_labels{
						created_date
						shipping_method
						warehouse
						source
						warehouse_id
						address{
							address1
							address2
							country
							city
							state
							zip
						}
						dimensions{
							weight
							height
							width
							length
						}
						shipment_line_items(first: 10){
							edges{
								node{
									quantity
								}
							}
						}
					}
				}
      }
    }
  }
}

Hi @jknechtv ,
If your just looking for the quantity of line items shipped under a label, what about…

query {
  shipments(order_id: "thisOrderId") {
    complexity
    request_id
    data(first: 10, sort: "created_date") {
      edges {
        node {
          shipping_labels {
            shipment_line_items (first:10) {
              edges {
                node {
                  quantity
                }
              }
            }
          }
        }
      }
    }
  }
}

Would that work for what you need?

Hi Theresa,

What you sent is basically the query I have in the original post

Hello @jknechtv!
Do you know how to paginate? That would alleviate the credit expenditure.

What you could do, for example, is using the mean or median for shipment_line_items to check if 10 is too much. That way, you might be able to reduce the number of credits you spend for each call.

With that setup, you could paginate the shipment_line_items pages, using the hasNextPage value to check if more results are missing for that node.

Then, for example, let say you decide on first:3 for shipment_line_items, you could use first:10 for shipments, spending 30 credits per call, which is the same amount you recover per second. This way, you will always have credits available.

From there on, you can make adjustments on how many nodes per edge you call, considering the amount you spend + the amount you recover, exceeding the recovery rate if you know this is a finite process and the rate you use will not get you to 0 credit while the process lasts.

Please let me know if there is something you don’t understand.
Have a great day!
TomasFD