Hello,
we are trying to update category and metafields using python API library but are unable to set category.
Adding code and error we get below:
api_version = '2024-07'
with shopify.Session.temp(shop_url, api_version, 'hidden'):
product = shopify.Product.find()
print(product[0].category)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-122-9a45f5223925> in <module>
3 # print(single_image[0].src)
4 product = shopify.Product.find()
----> 5 print(product[0].category)
6 # product = shopify.Product()
7 # product.title = "Shopify Logo T-Shirt"
c:\Users\root\AppData\Local\Programs\Python\Python37\lib\site-packages\pyactiveresource\activeresource.py in __getattr__(self, name)
915 if name in self.attributes:
916 return self.attributes[name]
--> 917 raise AttributeError(name)
918
919 def __setattr__(self, name, value):
AttributeError: category
We can set other fields like title.
Also, how would we set the values of attributes using python API library. For example:
Attributes:
- Age group: Adults
- Clothing features: Wrinkle resistant
- Color: Beige
- Dress occasion: Formal
- Dress style: Gown
- Fabric: Satin
- Neckline: Halter
- Pattern: Solid
- Size: One size
- Skirt/Dress length type: Maxi
- Sleeve length type: Sleeveless
- Target gender: Female
tedtate
2
Hi @aideveloper2 ,
I think the issue that you are having here is that the category field is not supported by the REST API. If you want to start using product categories you are going to need to migrate to GraphQL - https://github.com/Shopify/shopify_python_api?tab=readme-ov-file#graphql.
Its also worth mentioning that the Products REST API has been deprecated and will be going away next year - https://shopify.dev/changelog/deprecation-timelines-related-to-new-graphql-product-apis
We did that but run into another issue. When we run this:
mutation productCreate {
productCreate(input: {
title: "Linked option product test",
category: "gid://shopify/TaxonomyCategory/aa-1-13-7",
productOptions: [
{
name: "Size",
linkedMetafield: {
namespace: "shopify",
key: "size",
values: [
"gid://shopify/Metaobject/43003248699",
"gid://shopify/Metaobject/38602899515"
]
}
}
]
}), {
userErrors { message }
product {
id
metafields(first: 10) {
nodes {
namespace
key
value
}
}
options {
name
optionValues {
name
linkedMetafieldValue
}
}
}
}
}
we get this: {
“data”: {
“productCreate”: {
“userErrors”: [
{
“message”: “At least one value for the option linked to the ‘shopify.size’ metafield is invalid”
}
],
“product”: null
}
},
“extensions”: {
“cost”: {
“requestedQueryCost”: 18,
“actualQueryCost”: 10,
“throttleStatus”: {
“maximumAvailable”: 2000,
“currentlyAvailable”: 1990,
“restoreRate”: 100
}
}
}
}
And if we try the code here: https://shopify.dev/docs/apps/build/graphql/migrate/new-product-model/metafield-linked
we get another error / bug: {
“errors”: [
{
“message”: “Field ‘productCategory’ doesn’t exist on type ‘UserError’”,
“locations”: [
{
“line”: 6,
“column”: 9
}
],
“path”: [
“mutation CreateProductWithLinkedOptions”,
“productCreate”,
“userErrors”,
“productCategory”
],
“extensions”: {
“code”: “undefinedField”,
“typeName”: “UserError”,
“fieldName”: “productCategory”
}
},
{
“message”: “Field ‘productTaxonomyNodeId’ doesn’t exist on type ‘UserError’”,
“locations”: [
{
“line”: 11,
“column”: 9
}
],
“path”: [
“mutation CreateProductWithLinkedOptions”,
“productCreate”,
“userErrors”,
“productTaxonomyNodeId”
],
“extensions”: {
“code”: “undefinedField”,
“typeName”: “UserError”,
“fieldName”: “productTaxonomyNodeId”
}
},
{
“message”: “Field ‘options’ doesn’t exist on type ‘ProductCreatePayload’”,
“locations”: [
{
“line”: 13,
“column”: 7
}
],
“path”: [
“mutation CreateProductWithLinkedOptions”,
“productCreate”,
“options”
],
“extensions”: {
“code”: “undefinedField”,
“typeName”: “ProductCreatePayload”,
“fieldName”: “options”
}
}
]
}