# Category field not available when using Python API library

**URL:** <https://community.shopify.com/t/category-field-not-available-when-using-python-api-library/360572>\
**Category:** Tools\
**Tags:** Product-Tips, Setting-Up\
**Created:** [September 23, 2024, 8:22am UTC](https://community.shopify.com/t/category-field-not-available-when-using-python-api-library/360572 "2024-09-23T08:22:19Z")\
**Posts on this page:** 4\
**Page:** 1

## AI-generated summary

**Issue:** The `category` field is unavailable when using Shopify's Python REST API library, throwing an `AttributeError` when attempting to access `product[0].category`.

**Root Cause:** The REST API does not support the `category` field. The Products REST API has been deprecated and will be discontinued next year.

**Recommended Solution:** Migrate to GraphQL API, which supports product categories.

**Follow-up Problems:** After switching to GraphQL:
- First attempt using `productCreate` mutation with linked metafields returns error: "At least one value for the option linked to the 'shopify.size' metafield is invalid"
- Second attempt following official documentation produces schema errors: fields `productCategory`, `productTaxonomyNodeId`, and `options` don't exist on types `UserError` and `ProductCreatePayload`

**Status:** Unresolved. The user successfully identified the REST API limitation but encountered multiple GraphQL implementation errors, suggesting either API version mismatches or outdated documentation examples.

<div class="post-metadata">

**Author:** ![aideveloper2](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@aideveloper2](https://community.shopify.com/u/aideveloper2)\
**Post date:** [September 23, 2024, 8:22am UTC](https://community.shopify.com/t/category-field-not-available-when-using-python-api-library/360572/1 "2024-09-23T08:22:19Z")

</div>

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:

```auto
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

---

<div class="post-metadata">

**Author:** ![tedtate](https://avatars.discourse-cdn.com/v4/letter/t/2bfe46/32.png) [@tedtate](https://community.shopify.com/u/tedtate)\
**Post date:** [September 25, 2024, 7:16pm UTC](https://community.shopify.com/t/category-field-not-available-when-using-python-api-library/360572/2 "2024-09-25T19:16:41Z")

</div>

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](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](https://shopify.dev/changelog/deprecation-timelines-related-to-new-graphql-product-apis)

---

<div class="post-metadata">

**Author:** ![aideveloper2](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@aideveloper2](https://community.shopify.com/u/aideveloper2)\
**Post date:** [September 26, 2024, 11:08am UTC](https://community.shopify.com/t/category-field-not-available-when-using-python-api-library/360572/3 "2024-09-26T11:08:23Z")

</div>

We did that but run into another issue. When we run this:

```markup
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  
}  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![aideveloper2](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@aideveloper2](https://community.shopify.com/u/aideveloper2)\
**Post date:** [September 26, 2024, 2:13pm UTC](https://community.shopify.com/t/category-field-not-available-when-using-python-api-library/360572/4 "2024-09-26T14:13:28Z")

</div>

And if we try the code here: [https://shopify.dev/docs/apps/build/graphql/migrate/new-product-model/metafield-linked](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”  
}  
}  
]  
}
