Graphql - how to query abandonedCheckouts by id

Hi,

I am trying to filter the abandonedCheckouts by id, but it doesn’t work. As the document mentions, I should be able to query by id(integer). abandonedCheckouts - GraphQL Admin

First, I use
query {
abandonedCheckouts(first: 5) {
nodes {
id
}
}
}
I get a list of ids.
But when I query by id, it returns empty
query {
abandonedCheckouts(first: 5, query:“id:38786697298227”) {
nodes {
id
}
}
}


Any idea? Am I doing it wrong?

1 Like

Hey @Lei_Zou,

Thanks for sharing this. When I test on my end, I am seeing the same as well. I do notice our docs have this listed as a range query, so its more tailored for finding abandoned checkouts before or after a certain point.

For example, this works to find all of the abandoned checkouts that occurred before this ID:
abandonedCheckouts(first: 5, query:"id:<=12345678910")

For an exact match, I would recommend using the abandonmentByAbandonedCheckoutId - GraphQL Admin query.

Here’s a simplified example of what that will look like:

{
    abandonmentByAbandonedCheckoutId(
        abandonedCheckoutId: "gid://shopify/AbandonedCheckout/12345678910"
    ) {
        id
    }
}

Alternatively, you could also use a general query like below:

abandonedCheckouts(first: 5, query:"12345678910")

Let me know if either of these options will work for you.

I tried both approaches and they are working. I’ll go with abandonedCheckouts(first: 250, query: "12345678910") and verify the ID on my end.

Previously, I tried abandonedCheckouts(first: 5, query: "id:<=12345678910"), but it didn’t seem to return the correct results. Sometimes it returned nodes with IDs greater than the one provided. I couldn’t figure out the pattern.

Sounds like a good plan.

If you can, when you run in to unexpected query results add in the debugging headers mentioned here: Shopify API search syntax

This can be really useful to understand how the query is being parsed.

Range Query are not working as expected - I am using the filter specified in this doc abandonedCheckouts - GraphQL Admin - but not getting any results - please point out if I am querying incorrectly

Hey @Anmol_Gupta , from what I can see, you’re doing this correctly.

If some checkouts are not appearing, can you add in the pageInfo fields to ensure the results you’re looking for aren’t on other pages?

Hey, were you able to test a paginated query?

I’m not the OP but have also noticed this issue. It seems like a bug on Shopify’s end that id:XXX does not work, but plain XXX does work. This differs from how the bulk enddpoint works for collections, products, customers, etc.

We can work around it, but it’d be nice if they behaved the same as the others (and, in fact, the way that the documentation for abandonedCheckouts says it works.)

Thanks. I’m looking in to this.

Hey Anmol,

I can confirm that this query is not behaving as expected in my own test as well. Our team is looking at a fix for that. I don’t have a timeline at the moment, but will update here once there is.

The current best workaround would be to use the abandonmentByAbandonedCheckoutId query instead.