[Classification synchronisation](#classifications-synchronisation)
[Create classifications](#create-classifications)
[Edit classifications](#edit-classifications)
[Delete classifications](#delete-classifications)

---

!!!
Pushing classifications works the same way for **documents** and for **assets**. You can refer to the process below to import both. The import of classifications is optional for assets.
!!!

In order to import the hierarchy from your ERP, you will need to create and manage each of the [individual classification](https://docs.quable.com/v5-EN/docs/objects-and-attributes#classification) hierarchy levels. To create the hierarchy shown below, you need to create the top levels first and the lower (sub)levels second.

![This is a documents classification example](/static/images/classif.png "Document classification example")

![This is an assets classification example](/static/images/classif-assets.png "Asset classification example")

---

### Classifications synchronisation

In accordance with the implementation you define, your hierarchy in Quable PIM will possibily be identical to your ERP categories.
Once this is set, you should consider synchronizing your classification hierarchy in order to place your documents in it. 
There are two typical scenarios:

| **Use case**         | **Solution**                                |              **Pros / Cons**                   |
|----------------------|---------------------------------------------|----------------------------------------------- |
| Your classification hierarchy is fixed or changes very little | You don't need to run an automatic synchronization job, you can manage this manually. | Less code and more human processing.  |
|                         | You can run a synchronization job but launch it manually | More human processing but more reliable synchronization |
| Your classification hierarchy is not fixed or you want total control over the uploads| You can synchronize your classifications before pushing the documents and variants| Maximum control over imports|

!!!Why pushing classifications before [documents](/cookbooks/import-data/import-via-api/5-push--documents/) or [assets](/cookbooks/import-data/import-via-api/push-assets/)?
In order to import your documents and assets properly, you need to be able to classify them in a category. It is important to make sure that classifications exist prior to importing content into your Quable PIM or DAM.
!!!

---

### Available endpoints overview

Let's say your ERP has documents in the breadcrumb "Tops > Sweaters". You can choose to create 2 classifications : 
- *classification_tops*
- *classification_sweaters*

Below are the available endpoints to add, get or edit classifications:

**Gather all the classifications for the PIM catalog:**
[!badge variant="primary" text="GET"] /api/classifications?catalogs.id[]=PIM

**Get a specific classification, if it already exists:**
[!badge variant="primary" text="GET"] /api/classifications/_classification_sweaters_

**Create a new classification, if it does not exist already:**
[!badge variant="secondary" text="POST"] /api/classifications

**Update an existing classification:**
[!badge variant="warning" text="PUT"] /api/classifications/_classification_sweaters_

**Delete an existing classification:**
[!badge variant="danger" text="DELETE"] /api/classifications/_classification_sweaters_

---

## Create classifications

To create classifications, you must know :
- **where it will be located in the hierarchy**,
- **its unique identifier**
- **its parent classification's unique identifier**

You can also include attributes' values for the classification, in every locale.

### Endpoint

[!badge variant="primary" text="POST"] /api/classifications

!!!warning This endpoint is unitary
This endpoint is unitary and creates a single resource at a time.
!!!

---

### Body parameters

| Attribute status       |  Attribute name        |       Type      |           Description                                       |
|------------------------|------------------------|-----------------|-------------------------------------------------------------|
| Required               | [!badge variant="light" text="id"]    |     string      | The unique identifier of the classification to be created.        |
| Required               | [!badge variant="light" text="parent.id "] |     string      | The unique identifier of the parent classification. It defines its location in the hierarchy and is only required during classification creation  |
| Accepted               |  [!badge variant="light" text="active"]  |     boolean      | Usually, true |
| Accepted               |  [!badge variant="light" text="attributes"]  |     object      | Any attribute code with its value(s) (e.g., name in the example below) |

### Example

```python Create classifications
import requests
import json

url= "https://{{instance}}.quable.com.quable.com/api/classifications"
payload=json.dumps({
  "id": "classification_sweaters",
  "parent": {
    "id": "classification_tops"
  },
  "active": True,
  "attributes": {
    "quable_classification_name": {
      "en_US": "Sweaters",
      "fr_FR": "Pulls"
    }
  }
})
headers= {
  'Content-Type': 'application/json',
  'Authorization': 'Bearer ...'
}

response= requests.request("POST", url, headers=headers, data=payload)
```

---

## Edit Classifications

To edit a classification, you must know the classification's unique identifier.

### Endpoint

[!badge variant="primary" text="PUT"] /api/classifications/*[identifier]*

!!!warning This endpoint is unitary
This endpoint is unitary and modifies a single resource at a time
!!!
---

### Query parameters

|  Query Parameter name                                 |       Type             |   Description                                          |
|-------------------------------------------------|------------------------|--------------------------------------------------------|
| [!badge variant="light" text="identifier"]            |  string                |  Current unique identifier of the classification to update.  |

---

### Body parameters

| Attribute status       |  Attribute name        |       Type      |           Description                                       |
|------------------------|------------------------|-----------------|-------------------------------------------------------------|
| Required               | [!badge variant="light" text="id"]    |     string      | The current or new identifier of the classification        |
| Accepted               | [!badge variant="light" text="parent.id "] |     string      | The unique identifier of the parent classification.  |
| Accepted               |  [!badge variant="light" text="active"]  |     boolean      | Usually, true |
| Accepted               |  [!badge variant="light" text="attributes"]  |     object      | Any attribute code with its value(s) (e.g., name in the example below) |

---

### Example

```python Edit classification
import requests
import json

url = "https://{{instance}}.quable.com/api/classifications/classification_sweaters"
payload = json.dumps({
  "id": "classification_sweaters",
  "active": True,
  "attributes": {
    "quable_classification_name": {
      "en_US": "Jumpers",
      "fr_FR": "Pullover"
    }
  }
})
headers = {
		'Content-Type': 'application/json',
		'Authorization': 'Bearer ...'
}

response = requests.request("PUT", url, headers=headers, data=payload)

```

---

## Delete Classifications

It may become necessary at some point to delete a classifcation from Quable PIM (e.g., to synchronize with a change in your ERP).
To delete a classification, you must identify the classification's unique identifier.

!!!danger What happens when a classification is deleted
- All of its child classifications are also deleted.
- All related objects (documents, variants, assets) become orphans (unclassified).
!!!

---

### Endpoint

[!badge variant="primary" text="/DELETE"]/api/classifications/*[identifier]*
*'identifier' being the unique code of the classification to delete.*

---

### Example

```python Delete classification
import requests

url = "https://{{instance}}.quable.com/api/classifications/classification_sweaters"
headers= {
  'Content-Type': 'application/json',
  'Authorization': 'Bearer ...'
}

response= requests.request("DELETE", url, headers=headers)
```

---
