Hello
Because of our business needs, we need to be able to track the status of items within each order.
On the order details page, we see that the order is split into several packages.
For example, in the figure below, we can see that the order has been split into 2 packages
However, the results from the GraphQL API do not contain information about which package the items are assigned to.
Is there a way to get the items in the packages that we see in the current web page through the API?
Hi @jiasian ,
Just browsing through the API documentation, it looks like if you’re using the orders
query, you should be able to get to it from there. Instead of getting the line_items
of the order directly, go through the shipments
field and get the line_items from there instead. I think that should return which lines are in which shipments. Or, if you have the order_id (not the order_number!) then you can just query the shpiments directly using the order_id as a criteria.
Jeremy
Hello @jeremyw
Thank you for reply
I’m using the shipments API in the above. (ref: Examples – Developer Resources | ShipHero)
What I’m confused about is that using the API and only one shipment in the response from the API, but the shipment on the page is two.
The API mixes the results of the two shipments I see on the page.
Hi @jiasian!
What you see in the shared screenshot is a single shipment with two packages/labels. That is why you only get 1 shipment object returned, although you get both labels. You can tell if it is two separate shipments or one shipment with 2 labels because of the “1 of 2” and “2 of 2” text beside each tracking number.
To get what was in each package, your query should look something like this:
query{
shipments(order_id:"string"){
data{
edges{
node{
shipping_labels{
shipment_line_items{
edges{
node{
quantity <------- Shipped quantity in that package
line_item{
sku
quantity <------ Ordered quantity
quantity_shipped <------ Shipped quantity across all shipments/packages
}
}
}
}
}
}
}
}
}
}
You can find more info on the available fields for our queries and mutations in our schema: https://developer.shiphero.com/wp-content/uploads/spectaql/#query-shipments
You can also use our webhook to get this information: Webhooks – Developer Resources | ShipHero
BTW, thanks @jeremyw, for stepping in!
Have a nice day both!
1 Like
Hi @tomasfd
I use your example to query data, and got the error:
There are not enough credits to perform the requested operation, which requires 10101 credits, The max allowed for your account is 2002 credits per operation.`
So I separated it into two steps. First, I used the ‘get order’ API to retrieve the shipment ID. Then, I used the shipment ID to access the ‘get shipment’ API and retrieve the shipment line items.
It’s work for me, thank you.
Hi @jiasian,
That error occurs because there are 2 nested edges, each pulling 100 results, so it returns 100*100 results.
To control how many credits the query will need, you need to use the first clause in the edges. Here is our documentation on managing credits, throttling, and quotas. Getting Started – Developer Resources | ShipHero
It will also be beneficial to understand how pagination works in our API: GraphQL Primer – Developer Resources | ShipHero
To get it done in a single call, you could do the following:
query{
shipments(order_id:"470127524"){
data(first:1){
edges{
node{
shipping_labels{
legacy_id
shipment_line_items(first:10){
edges{
node{
quantity
line_item{
sku
quantity
quantity_shipped
}
}
}
}
}
}
}
}
}
}
Have an ice day!