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.
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
}
}
}
}
User | Count |
---|---|
25 | |
8 | |
7 | |
5 | |
4 |