> For the complete documentation index, see [llms.txt](https://apidocs.akinon.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://apidocs.akinon.com/commerce-openapis/admin/products/product-categories.md).

# Product Categories

Administrative endpoints for **product–category links** — the join records that file a product under one or more category nodes. Each record ties one product to one category node and optionally flags that link as the product's *main* category.

A product–category link is a thin association: a product reference, a category-node reference, and an `is_main` flag. The category nodes themselves are managed with the **Category Nodes** endpoints and the products with the **Products** endpoints; these endpoints only manage the links between them.

### Core Capabilities

**1. Link Listing & Filtering**

* Retrieve a paginated list of all product–category links.
* Filter by `id`, `product`, or `category` to find the links for a given product or category node.
* Order results with the `sort` parameter.

**2. Link Lifecycle Management**

* Create a link that files a product under a category node.
* Fully or partially update an existing link (for example, to move the `is_main` flag).
* Delete a link (**hard delete** — the record is permanently removed).

### Product–Category Fields

| Field      | Type              | Description                                                                        |
| ---------- | ----------------- | ---------------------------------------------------------------------------------- |
| `pk`       | integer           | The unique identifier of the link. Assigned by the server; read-only.              |
| `product`  | integer           | The identifier of the linked product. Required on create and full update.          |
| `category` | integer           | The identifier of the linked category node. Required on create and full update.    |
| `is_main`  | boolean or `null` | Whether this is the product's main category. Optional; defaults to `null` (unset). |

The pair (`product`, `category`) is **unique** — a product cannot be filed under the same category node twice. A duplicate is rejected with `400 Bad Request` carrying a `non_field_errors` entry.

### Filtering & Ordering

| Parameter  | Match | Notes                                                   |
| ---------- | ----- | ------------------------------------------------------- |
| `id`       | Exact | Filter by the link's own identifier.                    |
| `product`  | Exact | Keep only links for the given product identifier.       |
| `category` | Exact | Keep only links for the given category-node identifier. |

Use the `sort` query parameter to order on `pk`, `product`, `category`, or `is_main`; prefix with `-` for descending (e.g. `?sort=-pk`). No default ordering is applied.

### Deletion Behavior

`DELETE /product_category/{id}/` **permanently removes** the link record — there is no soft-delete or `is_active` flag on this resource. As a side effect, deleting a link refreshes the parent product's `modified_date` when that timestamp is older than 60 seconds, so downstream indexers pick up the change.

### Dynamic Settings & Environment Variables

No dynamic settings (`dj_dynamic_settings`) and no environment variables affect these endpoints. The `GROUPED_PRODUCT_PRICE_SELECTOR` and `LIST_SIMPLE_INSTEAD_OF_META` settings registered in `omnishop/catalogs/settings/conf.py` are consumed only by the product price and stock services, not by the product–category links.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://apidocs.akinon.com/commerce-openapis/admin/products/product-categories.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
