A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
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.
😕NOTE: I'm testing these queries at https://shopify.dev/graphiql/admin-graphiql
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 😕
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.
Developer Support @ Shopify
- Was this reply helpful? Click Like to let us 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