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.