Shopify GraphQL API productsCount query not working

The new productsCount - GraphQL Admin API is not working

When I tried the following example cURL it is returning errors in the response.

curl -X POST \
https://your-development-store.myshopify.com/admin/api/2025-01/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "query { productsCount(query: \"id:>=1000\") { count } }"
}'

Response:

{
    "errors": [
        {
            "message": "Field 'productsCount' doesn't exist on type 'QueryRoot'",
            "locations": [
                {
                    "line": 1,
                    "column": 9
                }
            ],
            "path": [
                "query",
                "productsCount"
            ],
            "extensions": {
                "code": "undefinedField",
                "typeName": "QueryRoot",
                "fieldName": "productsCount"
            }
        }
    ]
}

Even using the exact example Shopify docs is not working. So I’m not sure what I’m doing wrong here.

That’s odd… this query seems to be working for me:

curl -X POST \
https://myteststore.myshopify.com/admin/api/2025-01/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: shpat_xxxxxxxxxxxxxxxxx' \
-d '{
"query": "query { productsCount(query: \"id:>=1000\") { count } }"
}'

I do the get the ‘field doesn’t exist’ error message if I try older API versions though but it looks like you’re using 2025-01 as well? A few things I’d test:

  • Double-check that you’re on 2025-01, maybe try 2024-10 or unstable also just to make sure
  • Do other queries, like query { shop { name } } work for you?
  • Does this work on another store besides the one you’re testing on?

Best,
Daniel

Just to confirm, do you have read_products access scope? Which API version are you on?

I have read_products access scope for the token the that I used.

I was under the assumption that calling /admin/api/graphql.json without the API version will take the latest stable version. But it seems that it was not the case. When I added the version to the PATH (i.e., /admin/api/2025-01/graphql.json) the API is giving success response with the data.

Thank you @Liam-Shopify & @Daniel_Ablestar for sharing your inputs.

1 Like

Great to hear this worked Kiran!

1 Like