How to get single product with GraphQL Admin API

Topic summary

A user encountered an error when trying to query a single product using a variable in Shopify’s GraphQL Admin API: “Variable $id of type ID! was provided invalid value.” The query worked when hardcoding the product ID directly but failed when using a variable.

Key Points:

  • The query structure itself was correct: query GetProductsById($id: ID!) { product(id: $id) { title } }
  • The issue was related to how variables were being passed, not the query syntax
  • Another user pointed out the need to provide the variable value in the Query Variables section at the bottom of the GraphQL explorer interface

Resolution:
The original poster confirmed the issue was resolved, though they weren’t entirely sure what changed. The correct format requires:

  • Defining the query with the variable parameter
  • Separately providing the variable value in JSON format: {"id": "gid://shopify/Product/1974208364566"}

A Shopify support representative confirmed the query structure was correct and provided a reference screenshot showing proper variable definition format.

Summarized with AI on November 14. AI used: claude-sonnet-4-5-20250929.

Hi everyone!

I’m quite new to Shopify and GraphQL but I have some coding experience at hand..

I’m trying to fetch single product with Admin API but it is whining about “Variable $id of type ID! was provided invalid value”.

What I’m trying to do is as follows:

query GetProductsById($id: ID!) {
  product(id: $id) {
    title
  }
}

When I do the almost the same, I can get product by id:

query {
  product(id: "gid://shopify/Product/1974208364566") {
    title
  }
}

Now I’m not sure what I’m doing wrong here, when I’m trying the same as above while fetching all products it goes well and there is no problem with my query.

Please note that I have also tried with encoding GID to base64 but with same error. Also I have tried with “node” fragments which gives me the same error.

Error:

{
  "errors": [
    {
      "message": "Variable $id of type ID! was provided invalid value",
      "locations": [
        {
          "line": 1,
          "column": 23
        }
      ],
      "extensions": {
        "value": null,
        "problems": [
          {
            "path": [],
            "explanation": "Expected value to not be null"
          }
        ]
      }
    }
  ]
}

Somehow it seems that variables are not passed, or I’m crazy.

You have to provide the variable’s value in the Query Variables section at the bottom of the form. See screen shot below. Hope this helps!

Thank you for the fast response,

I’m doing it quite the same as shown bellow, but somehow I’m getting this error and you don’t :confused:

It’s solved now, I’m not quite sure what I did differently but somehow it’s started to work. Still their online explorer does not work.

Thank you for your support, much appreciated!

Glad it’s working. The other thing to check is that the ID is actually one that is defined. Easiest way to grab a few product ID’s to test in your query above is something like this. Copy one of these and paste into your query variable. That should work!

{
  products(first: 5) {
    edges {
      node {
        id
      }
    }
  }
}

{
product(id: “gid://shopify/Product/8444550185239”) {
title
description
onlineStoreUrl
priceRangeV2 {
minVariantPrice {
amount
currencyCode
}
}
}
}

Hey @marshall2056 ! Thanks for sharing those examples. The query looks correct. What are you defining for the variables?

It should look like this:

query GetProductsById($id: ID!) {> product(id: $id) {> title> }> }

Variables:

{> “id”: “gid://shopify/Product/1974208364566”> }

Screenshot from Graphiql for reference.

Hope that helps!

  • Kyle G.