A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
I have a developer test store, and I am looking at Graphql for accessing the store data. I can query a particular product by putting id:"gid://shopify/Product/..." in the query filter. However the documentation for ID says:
The ID scalar type represents a unique identifier, often used to refetch an object or as key for a cache. The ID type appears in a JSON response as a String; however, it is not intended to be human-readable. When expected as an input type, any string (such as "4") or integer (such as 4) input value will be accepted as an ID.
But there seems to be no way to assign a product an integer id. Using the number at the end of the gid URL doesn't work. Am I missing something?
Solved! Go to the solution
This is an accepted solution.
Hi Matthew49,
The `gid://shopify/Product/... ID` you're seeing is a globally unique identifier (gid) that Shopify uses to uniquely identify resources across the entire system. The number at the end of this gid is the unique identifier for that resource within its type. For example, in `gid://shopify/Product/12345`, `12345` is the unique identifier for a product.
However, when querying for a product using GraphQL, you need to use the full gid (`gid://shopify/Product/12345`), not just the unique identifier at the end. This is because the gid includes information about the type of the resource (in this case, Product), which is necessary for the GraphQL API to correctly identify and fetch the resource.
If you're trying to fetch a product using just an integer ID, you would need to use the REST API instead of the GraphQL API. The REST API allows you to fetch resources using just their integer ID. For example, you could fetch a product using a GET request to `/admin/api/2023-04/products/12345.json`.
Hope this helps!
Liam | Developer Advocate @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
This is an accepted solution.
Hi Matthew49,
The `gid://shopify/Product/... ID` you're seeing is a globally unique identifier (gid) that Shopify uses to uniquely identify resources across the entire system. The number at the end of this gid is the unique identifier for that resource within its type. For example, in `gid://shopify/Product/12345`, `12345` is the unique identifier for a product.
However, when querying for a product using GraphQL, you need to use the full gid (`gid://shopify/Product/12345`), not just the unique identifier at the end. This is because the gid includes information about the type of the resource (in this case, Product), which is necessary for the GraphQL API to correctly identify and fetch the resource.
If you're trying to fetch a product using just an integer ID, you would need to use the REST API instead of the GraphQL API. The REST API allows you to fetch resources using just their integer ID. For example, you could fetch a product using a GET request to `/admin/api/2023-04/products/12345.json`.
Hope this helps!
Liam | Developer Advocate @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
Thank you for that. It's slightly confusing that the GraphQL documentation says you can use an integer id as input. I'll stick with GraphQL as it allows me just to retrieve specific attributes of the product, whereas I believe the Shopify REST API can only return the whole product. I'm used to working with the Magento REST API which allows lots of flexibility in what you search for and what you return!
Thanks again.