> For the complete documentation index, see [llms.txt](https://docs.extracta.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.extracta.ai/document-classification-api/api-endpoints-document-classification/3.-update-classification.md).

# 3. Update classification

<mark style="color:orange;">`PATCH`</mark> `/documentClassification/updateClassification`

Updates an existing document classification process by modifying specific parameters within the classification details. This endpoint is useful for adjusting document types, keywords, or metadata without recreating the entire classification setup.

## Server URL

```
https://api.extracta.ai/api/v1
```

## Headers

| Name          | Value              |
| ------------- | ------------------ |
| Content-Type  | `application/json` |
| Authorization | `Bearer <token>`   |

## Body

<table data-full-width="false"><thead><tr><th width="183">Name</th><th width="125.609375">Type</th><th width="104">Required</th><th width="332.07421875">Description</th></tr></thead><tbody><tr><td><code>classificationId</code></td><td>string</td><td><code>true</code></td><td>Unique identifier for the classification.</td></tr><tr><td><code>name</code></td><td>string</td><td><code>true</code></td><td>A name for the classification.</td></tr><tr><td><code>description</code></td><td>string</td><td><code>true</code></td><td>A description for the classification.</td></tr><tr><td><code>documentTypes</code></td><td>list&#x3C;object></td><td><code>true</code></td><td>An array of objects, each specifying a document type.</td></tr></tbody></table>

## Body Example

```json
{
    "classificationId": "classificationId",
    "classificationDetails": {
        "name": "Financial Document Classifier - updated",
        "description": "Classifies uploaded documents into predefined financial document types. - updated",
        "documentTypes": [
            {
                "name": "Invoice",
                "description": "Standard commercial invoice from vendors or suppliers.",
                "uniqueWords": [
                    "invoice number",
                    "bill to",
                    "total amount"
                ],
                "extractionId": "-OPXR1F82I0cRYJPcHNo"
            }
        ]
    }
}
```

## Code Example

{% tabs %}
{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

async function updateClassification(token, classificationId, classificationDetails) {
    const url = "https://api.extracta.ai/api/v1/documentClassification/updateClassification";

    try {
        const response = await axios.patch(url, {
            classificationId,
            classificationDetails
        }, {
            headers: {
                'Content-Type': 'application/json',
                'Authorization': `Bearer ${token}`
            }
        });

        return response.data;
    } catch (error) {
        throw error.response ? error.response.data : new Error('An unknown error occurred');
    }
}

async function main() {
    const token = 'apiKey';
    const classificationId = 'classificationId';
    const classificationDetails = {
        "name": "Financial Document Classifier - updated",
        "description": "Classifies uploaded documents into predefined financial document types. - updated",
        "documentTypes": [
            {
                "name": "Invoice",
                "description": "Standard commercial invoice from vendors or suppliers.",
                "uniqueWords": [
                    "invoice number",
                    "bill to",
                    "total amount"
                ],
                "extractionId": "-OPXR1F82I0cRYJPcHNo"
            }
        ]
    };

    try {
        const response = await updateClassification(token, classificationId, classificationDetails);
        console.log("Classification Updated:", response);
    } catch (error) {
        console.error("Failed to update classification:", error);
    }
}

main();

```

{% endtab %}

{% tab title="Python" %}

```python
import requests

def update_classification(token, classification_id, classification_details):
    url = "https://api.extracta.ai/api/v1/documentClassification/updateClassification"
    headers = {"Content-Type": "application/json", "Authorization": f"Bearer {token}"}
    payload = {
        "classificationId": classification_id,
        "classificationDetails": classification_details
    }

    try:
        response = requests.patch(url, json=payload, headers=headers)
        response.raise_for_status()
        return response.json()
    except requests.RequestException as e:
        print(f"Failed to update classification: {e}")
        return None

# Example usage
if __name__ == "__main__":
    token = "apiKey"
    classification_id = "classificationId"
    classification_details = {
        "name": "Financial Document Classifier - updated",
        "description": "Classifies uploaded documents into predefined financial document types. - updated",
        "documentTypes": [
            {
                "name": "Invoice",
                "description": "Standard commercial invoice from vendors or suppliers.",
                "uniqueWords": [
                    "invoice number",
                    "bill to",
                    "total amount"
                ],
                "extractionId": "-OPXR1F82I0cRYJPcHNo"
            }
        ]
    }

    response = update_classification(token, classification_id, classification_details)
    print("Classification Updated:", response)

```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

function updateClassification($token, $classificationId, $classificationDetails) {
    $url = 'https://api.extracta.ai/api/v1/documentClassification/updateClassification';

    // Initialize cURL session
    $ch = curl_init($url);

    // Prepare the payload with classificationId and classificationDetails
    $payload = json_encode([
        'classificationId' => $classificationId,
        'classificationDetails' => $classificationDetails
    ]);

    // Set cURL options
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
    curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        'Content-Type: application/json',
        'Authorization: Bearer ' . $token,
    ]);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    try {
        // Execute cURL session
        $response = curl_exec($ch);

        // Check for cURL errors
        if (curl_errno($ch)) {
            throw new Exception('Curl error: ' . curl_error($ch));
        }

        return $response;
    } catch (Exception $e) {
        return 'Error: ' . $e->getMessage();
    } finally {
        curl_close($ch);
    }
}

// Example usage
$token = 'apiKey';
$classificationId = 'classificationId';
$classificationDetails = [
    "name" => "Updated Financial Classifier",
    "description" => "Updated description for the financial document classifier.",
    "documentTypes" => [
        [
            "name" => "Invoice",
            "description" => "Updated invoice description.",
            "uniqueWords" => ["invoice number", "billing address"],
            "extractionId" => "updatedExtract123"
        ],
        [
            "name" => "Receipt",
            "description" => "Retail receipts for in-store purchases.",
            "uniqueWords" => ["store id", "cashier", "receipt total"]
        ]
    ]
];

try {
    $response = updateClassification($token, $classificationId, $classificationDetails);
    echo $response;
} catch (Exception $e) {
    echo "Failed to update classification: " . $e->getMessage();
}

?>

```

{% endtab %}
{% endtabs %}

## Responses

{% tabs %}
{% tab title="200" %}

```json
{
    "status": "updated",
    "updatedAt": 1746720927500,
    "classificationId": "-OPkce8E1CuEQeHDZetx"
}
```

{% endtab %}

{% tab title="400" %}

```json
{
    "status": "error",
    "message": "Classification does not exist",
    "classificationId": "-OPkce8E1CuEQeHDZetxs"
}
```

{% endtab %}

{% tab title="500" %}

```json
{
    "status": "error",
    "message": "Error updating classification"
}
```

{% endtab %}
{% endtabs %}


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.extracta.ai/document-classification-api/api-endpoints-document-classification/3.-update-classification.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
