shopify: Can't update product field via GraphQL due to "Field is not defined on ProductInput" - Stack

Trying to update the category which is a documented field (and is available in the GraphiQL Shopify app

Trying to update the category which is a documented field (and is available in the GraphiQL Shopify app), but the API complains that it's not valid:

{'message': 'Variable $input of type ProductInput! was provided invalid value for category (Field is not defined on ProductInput)', 'locations': [{'line': 1, 'column': 24}], 'extensions': {'value': {'id': 'gid://shopify/Product/9819449721123', 'title': "Dustin's Men's Fake Jacket for Testing 2", 'category': 'gid://shopify/TaxonomyCategory/aa-1-10-2'}, 'problems': [{'path': ['category'], 'explanation': 'Field is not defined on ProductInput'}]}}

The request is:

mutation ProductUpdate($input: ProductInput!) {                                 
  productUpdate(input: $input) {                                                
    product {                                                                   
      id                                                                        
      title                                                                     
      category {                                                                
        id                                                                      
      }                                                                         
    }                                                                           
    userErrors {                                                                
      field                                                                     
      message                                                                   
    }                                                                           
  }                                                                             
}                                 

The variables are:

{                                                                   
  "input": {                                                                    
    "id": "gid://shopify/Product/9819449721123",                                
    "category": "gid://shopify/TaxonomyCategory/aa-1-10-2",                     
  }                                                                             
}  

Should the selector be category { id } instead of category in the request, or should I be putting something like "category": { "id": "..." }" in the variables?

Trying to update the category which is a documented field (and is available in the GraphiQL Shopify app), but the API complains that it's not valid:

{'message': 'Variable $input of type ProductInput! was provided invalid value for category (Field is not defined on ProductInput)', 'locations': [{'line': 1, 'column': 24}], 'extensions': {'value': {'id': 'gid://shopify/Product/9819449721123', 'title': "Dustin's Men's Fake Jacket for Testing 2", 'category': 'gid://shopify/TaxonomyCategory/aa-1-10-2'}, 'problems': [{'path': ['category'], 'explanation': 'Field is not defined on ProductInput'}]}}

The request is:

mutation ProductUpdate($input: ProductInput!) {                                 
  productUpdate(input: $input) {                                                
    product {                                                                   
      id                                                                        
      title                                                                     
      category {                                                                
        id                                                                      
      }                                                                         
    }                                                                           
    userErrors {                                                                
      field                                                                     
      message                                                                   
    }                                                                           
  }                                                                             
}                                 

The variables are:

{                                                                   
  "input": {                                                                    
    "id": "gid://shopify/Product/9819449721123",                                
    "category": "gid://shopify/TaxonomyCategory/aa-1-10-2",                     
  }                                                                             
}  

Should the selector be category { id } instead of category in the request, or should I be putting something like "category": { "id": "..." }" in the variables?

Share Improve this question asked Mar 3 at 3:10 Dustin OpreaDustin Oprea 10.3k17 gold badges72 silver badges112 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Make sure the API version matches the documentation that you're looking at.

The product category update works fine:

# Request

q = """\
mutation ProductUpdate($input: ProductInput!) {
  productUpdate(input: $input) {
    product {
      id
    }
    userErrors {
      field
      message
    }
  }
}
"""

# Variables

v = {
  "input": {
    "id": "gid://shopify/Product/9819449721123",
    "category": "gid://shopify/TaxonomyCategory/aa-1-10-2",
  }
}

# Response

{
    "data":
    {
        "productUpdate":
        {
            "userErrors":
            []
        }
    },
    "extensions":
    {
        "cost":
        {
            "requestedQueryCost": 10,
            "actualQueryCost": 10,
            "throttleStatus":
            {
                "maximumAvailable": 20000.0,
                "currentlyAvailable": 19990,
                "restoreRate": 1000.0
            }
        }
    }
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745111177a4611860.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信