Hi.
I’ve had a pretty good search and can’t find any documentation or examples to solve an issue I’m having.
I’m trying to call the productCreate mutation (but this problem type would apply to any query really), to add a product to our store but have been unable to figure out what format to pass enums in when they are in a “variables” declaration.
Here is a cutdown version of the mutation:
mutation ProductMutation($add0Input: ProductInput!) {
add0: productCreate(input: $add0Input) {
product {
id
}
shop {
id
}
userErrors {
field
message
}
}
}
And here is the matching variables declaration:
{
"add0Input": {
"handle": "XXXX",
"title": "Product Title",
"descriptionHtml": "
Product Description
",
"variants": [
{
"sku": "XXXX",
"weight": 1,
"price": "179.96",
"taxable": true,
"inventoryItem": {
"tracked": false
}
}
],
"collectionsToJoin": [
"gid://shopify/Collection/111111111"
],
"images": [
{
"src": "https://example.com/files/shopify-inventory/image.jpg",
"altText": "product"
}
],
"vendor": "Us",
"status": "ACTIVE"
}
}
This gets me back this error:
{
"errors": [
{
"message": "Variable $add0Input of type ProductInput! was provided invalid value for status (Field is not defined on ProductInput)",
"locations": [
{
"line": 2,
"column": 26
}
],
"extensions": {
"value": {
"handle": "XXXX",
"title": "Product Title",
"descriptionHtml": "
Product Description
",
"variants": [
{
"sku": "XXXX",
"weight": 1,
"price": "179.96",
"taxable": true,
"inventoryItem": {
"tracked": false
}
}
],
"collectionsToJoin": [
"gid://shopify/Collection/111111111"
],
"images": [
{
"src": "https://example.com/files/shopify-inventory/image.jpg",
"altText": "product"
}
],
"vendor": "Us",
"status": "ACTIVE"
},
"problems": [
{
"path": [
"status"
],
"explanation": "Field is not defined on ProductInput"
}
]
}
}
]
}
So it appears I can’t pass an enum as a JSON String (since it’s not a string), but you also can’t just use the unquoted value as that’s not a valid JSON type.
Here is the documentation for the ProductStatus type:
https://shopify.dev/docs/admin-api/graphql/reference/products-and-collections/productstatus
Can anyone point to some relevant documentation, or better yet show a working example?
Thanks.