A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
I'm trying (and failing) to use the GraphQL API to add/update a private metafield on the Shop object using the privateMetafieldUpsert mutation.
I can get this to work fine on a Product object, but when it is given the ID of a Shop object it fails with the error "invalid id".
For example...
Mutation:
mutation ($input: PrivateMetafieldInput!) {
privateMetafieldUpsert(input: $input) {
privateMetafield {
namespace
key
value
}
userErrors {
field
message
}
}
}
Variables: (shop ID has been changed)
{
"input": {
"owner": "gid://shopify/Shop/99999999",
"namespace": "abc",
"key": "xyz",
"valueInput": {
"value": "{}",
"valueType": "JSON_STRING"
}
}
}
Result:
{
"data": {
"privateMetafieldUpsert": null
},
"errors": [
{
"message": "invalid id",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"privateMetafieldUpsert"
]
}
],
"extensions": {
"cost": {
"requestedQueryCost": 10,
"actualQueryCost": 1,
"throttleStatus": {
"maximumAvailable": 1000,
"currentlyAvailable": 999,
"restoreRate": 50
}
}
}
}
Does anyone know why this is failing?
Solved! Go to the solution
This is an accepted solution.
Hi, Richard687.
This is not the most obvious thing, but you can create a private metafield on a shop simply by omitting the owner. It will default to the current shop as the owner.
Hope that helps.
To learn more visit the Shopify Help Center or the Community Blog.
This is an accepted solution.
Hi, Richard687.
This is not the most obvious thing, but you can create a private metafield on a shop simply by omitting the owner. It will default to the current shop as the owner.
Hope that helps.
To learn more visit the Shopify Help Center or the Community Blog.
Many thanks. That worked nicely.