Access a community of over 900,000 Shopify Merchants and Partners and engage in meaningful conversations with your peers.
Hi, I want to get the latest orders of a particular customer using storefront api. However, when I try to get the last 10 orders of a customer, it show an error "using last without before is not supported". I also tried to use the sortKey field but it seems only support sorting in ascending order. So, what should I do in order to simply get the last n orders of a customer?
query { customer(customerAccessToken: "xxxxx") { orders(last: 10) { edges { node { id name shippingAddress { formatted } lineItems(first: 250) { edges { node { title quantity discountAllocations { allocatedAmount { currencyCode amount } } variant { image { originalSrc } priceV2 { currencyCode amount } compareAtPriceV2 { currencyCode amount } } } } } subtotalPriceV2 { currencyCode amount } totalShippingPriceV2 { currencyCode amount } totalTaxV2 { currencyCode amount } totalPriceV2 { currencyCode amount } processedAt } } } } }
Any update on this? According to the https://www.howtographql.com/ tutorial referenced by Shopify 'last: 10' should work suggesting this is a Shopify thing... So, an answer/documentation would be appreciated.
The example:
https://www.howtographql.com/basics/1-graphql-is-the-better-rest/
However, this:
{ customers(last:10) { edges { node { id, firstName, ordersCount, lastOrder {createdAt} } } } }
Returns:
{ "message": "using last without before is not supported", "locations": [ { "line": 10, "column": 5 } ], "path": [ "customers" ] }
Am I meant to pretend there is no 'last' and instead use 'first:10, reverse:true' instead?
Thanks.
Also having the same issue. Error: using last without before is not supported
The documentation doesn't mention that. It simply says:
last ( Int ) | Returns up to the last n elements from the list. |
Any help would be appreciated.
@Codesto1 - this looks like it might be a workaround for the API bug:
'first:10, reverse:true'
But I've not tested it thoroughly. Ideally, 'last:n' would be implemented correctly.
'first:10, reverse:true'
is not equal to
'last:10'
Imagine you have 20 data
[1,2,3....17,18,19,20]
The 1st approach will return
[10,9,8,7...3,2,1]
while the 2nd will return
[20,19,18....12,11,10]
Thanks for confirming my suspicions. So, we just need 'last:10' support, or at least documentation.
bump thread
I am having this exact same issue.
customer(customerAccessToken: "${customerAccessToken}") { orders(last: 10) {...} }
What happen if we use the sortKey like this:
orders(first: 10, reverse: true, sortKey: CREATED_AT) {...}
Is that possible?
I posted this issue here https://stackoverflow.com/questions/62765178/graphql-error-using-last-without-before-is-not-supporte... and I got an answer from another dev already.
bump has anyone found a solution to this?
same, "last" don't work :'(
Actually
first: 1, reverse: true
does return last order. just checked
And, just FYI, You can combine this reverse field with the sortkey of your desire, as in
products(first: 10, query: "tag:foobar", sortKey:UPDATED_AT, reverse: true )
User | RANK |
---|---|
10 | |
9 | |
9 | |
8 | |
7 |