Hey,
This request ID: 5f342f83566216d4eb447366 gets the first ~100 line items with a shipments query but not all of the line items on the order. Is there a way I can get all the line items?
Thanks,
Orion
Hey,
This request ID: 5f342f83566216d4eb447366 gets the first ~100 line items with a shipments query but not all of the line items on the order. Is there a way I can get all the line items?
Thanks,
Orion
Hey @Orion,
100 items is the maximum number to be returned in a single call to the API. In order to get more items, you’ll have to do “paging”. Basically, it’s when you send the same query multiple times, but you tell it where to pick up in the results using a “cursor”.
Check out: https://developer.shiphero.com/graphql-primer/#pagination
Jeremy
Hi Jeremy, I do already have paging for this shipments query, however, the next page goes to the next order’s shipment(s), not the rest of the items for the first order.
Oh! I completely misunderstood. Sorry about that!
It looks like the line items have their own pageInfo, cursors, and filters. (after, before, first, etc) My guess is you would need to apply the paging logic at the line level first, wait to get back hasNextPage: False
for the lines, and then continue it for the order level. I’ve never tried it myself, though.
Hi Jeremy,
No worries! Is it possible to put the cursor for line items within the shipments query (which right now just has cursor for next shipment), or would that need to be for an order query? If possible, can you please provide a graphQL example of the first scenario? I can use an orders query with first: 151 to get the 151 line items on the order, but these may not all be related to what is being shipped. Is it not possible to just ask for first: 151 in the shipments query’s line_items section? Thanks
So, I was able to get all 151 using “line_items(first: 200)” in the shipment query, although it also uses 201 credits. I’m wondering if there is a way to have the “first” line_items function return just the exact amount of lines that is in the order, or do we always have to send the amount in the order or request more lines than are in the order to make sure we get them all?
Hi @Orion,
Regarding your first question about if you need to use the orders query, no, you don’t. That was just my example. If you want to do it with the shipments query, it would, at a minimum, look like this:
query {
shipments {
request_id
data (after: "shipment_cursor_here") {
pageInfo {
hasNextPage
endCursor # <- your next "after" cursor for the shipments
}
edges {
node {
id
line_items (after: "line_item_cursor_here") {
pageInfo {
hasNextPage
endCursor # <- your next "after" cursor for the line_items
}
edges {
node {
line_item_id
quantity
}
}
}
}
}
}
}
}
I find it a bit odd that you’re able to get back 151 lines in a single call. Usually they have it capped at 100 records returned, even if you request more. Maybe @tomasw or someone else with ShipHero can shine some light on that.
Regarding your second question, no, there’s no way to get it to match the number of credits used for the number of records getting returned. It goes by what is requested. So if you request the first 100, it’s going to use at least 101 credits (1 credit is for the call itself, and then the rest depends on the complexity of the query), even if there is only 1 record to return.
Thanks for the help, Jeremy. Is there a query that can give us the number of line items on an order?
No problem, Orion.
I’m not aware of a query that will do that. But then again, I’m just another end-user like yourself. You can double check the schema docs to see if you can spot one, but I didn’t see one just glancing through. Someone from ShipHero may have to weigh in on that to let us know for sure.
Jeremy
Hi @Orion
Thanks for adding all those details @jeremyw! and I apologize for my delayed response about this
Unfortunately, there is no way of knowing the number of line items on an order (other than actually querying for the order and checking how many it has)
Also, the shipment might not have all of the line items in the order, for example, when an order gets partially shipped.
You could also use the following flow:
Please let me know if there is anything else I could help with, and if a Feature Request to be able to see how many line item a order has would help.
Thanks in advance!
Tom