> ## Documentation Index
> Fetch the complete documentation index at: https://docs.revreply.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Classify an Email

> Classifies an email and returns the resulting classification.

<Badge color="blue">POST</Badge> `https://api.revreply.com/v1/response/classify`

<Note>
  This endpoint requires authentication.
</Note>

## Try it

Use the following request to classify an email:

<Tabs>
  <Tab title="cURL">
    ```bash theme={null}
    curl -X POST "https://api.revreply.com/v1/response/classify" \
      -H "Authorization: Bearer <YOUR_JWT>" \
      -H "Accept: application/json" \
      -H "Content-Type: application/json" \
      -d '{"email_body":"Thanks for reaching out. I am interested in learning more.","thread_id":"abc123xyz"}'
    ```
  </Tab>

  <Tab title="JavaScript">
    ```javascript theme={null}
    const response = await fetch(
      "https://api.revreply.com/v1/response/classify",
      {
        method: "POST",
        headers: {
          "Authorization": "Bearer <YOUR_JWT>",
          "Accept": "application/json",
          "Content-Type": "application/json"
        },
        body: JSON.stringify({
          email_body: "Thanks for reaching out. I am interested in learning more.",
          thread_id: "abc123xyz"
        })
      }
    );
    const data = await response.json();
    console.log(data);
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={null}
    import requests

    response = requests.post(
        "https://api.revreply.com/v1/response/classify",
        headers={
            "Authorization": "Bearer <YOUR_JWT>",
            "Accept": "application/json",
            "Content-Type": "application/json",
        },
        json={
            "email_body": "Thanks for reaching out. I am interested in learning more.",
            "thread_id": "abc123xyz",
        },
    )
    data = response.json()
    print(data)
    ```
  </Tab>

  <Tab title="PHP">
    ```php theme={null}
    <?php
    $ch = curl_init("https://api.revreply.com/v1/response/classify");

    curl_setopt_array($ch, [
        CURLOPT_POST => true,
        CURLOPT_HTTPHEADER => [
            "Authorization: Bearer <YOUR_JWT>",
            "Accept: application/json",
            "Content-Type: application/json",
        ],
        CURLOPT_POSTFIELDS => json_encode([
            "email_body" => "Thanks for reaching out. I am interested in learning more.",
            "thread_id" => "abc123xyz",
        ]),
        CURLOPT_RETURNTRANSFER => true,
    ]);

    $response = curl_exec($ch);
    curl_close($ch);
    echo $response;
    ```
  </Tab>

  <Tab title="Go">
    ```go theme={null}
    package main

    import (
        "bytes"
        "fmt"
        "net/http"
    )

    func main() {
        body := []byte(`{"email_body":"Thanks for reaching out. I am interested in learning more.","thread_id":"abc123xyz"}`)

        req, _ := http.NewRequest(
            "POST",
            "https://api.revreply.com/v1/response/classify",
            bytes.NewBuffer(body),
        )

        req.Header.Set("Authorization", "Bearer <YOUR_JWT>")
        req.Header.Set("Accept", "application/json")
        req.Header.Set("Content-Type", "application/json")

        client := &http.Client{}
        response, _ := client.Do(req)
        fmt.Println(response.Status)
    }
    ```
  </Tab>
</Tabs>

## Authentication

This endpoint uses Bearer authentication with a JWT.

## Request

### Headers

| Header          | Type     | Required | Description                                                    |
| --------------- | -------- | -------- | -------------------------------------------------------------- |
| `Authorization` | `string` | Yes      | Bearer token used to authenticate the request.                 |
| `Accept`        | `string` | Yes      | Specifies that the client expects the response in JSON format. |
| `Content-Type`  | `string` | Yes      | Specifies that the request body is formatted as JSON.          |

```http theme={null}
Authorization: Bearer <YOUR_JWT>
Accept: application/json
Content-Type: application/json
```

### Body

The request body uses the `ClassifyResponseRequest` schema.

| Field               | Type             | Required | Description                   | Example                                                      |
| ------------------- | ---------------- | -------- | ----------------------------- | ------------------------------------------------------------ |
| `email_body`        | `string`         | Yes      | Email content to classify.    | `Thanks for reaching out. I am interested in learning more.` |
| `thread_id`         | `string \| null` | No       | Email thread identifier.      | `abc123xyz`                                                  |
| `email_thread_json` | `string \| null` | No       | Serialized email thread data. | `""`                                                         |
| `full_thread_json`  | `string \| null` | No       | Serialized full thread data.  | `""`                                                         |

### Request structure

```json theme={null}
{
  "email_body": "Thanks for reaching out. I am interested in learning more.",
  "thread_id": "abc123xyz",
  "email_thread_json": "",
  "full_thread_json": ""
}
```

### Request examples

The request is a `POST` request to:

```text theme={null}
https://api.revreply.com/v1/response/classify
```

## Response

### Response structure

A successful request returns the classification assigned to the email.

| Field                 | Type      | Required | Description                                      |
| --------------------- | --------- | -------- | ------------------------------------------------ |
| `success`             | `integer` | Yes      | Indicates whether classification was successful. |
| `data`                | `object`  | Yes      | Classification result.                           |
| `data.classification` | `string`  | Yes      | Classification assigned to the email.            |

### Response example

```json theme={null}
{
  "success": 1,
  "data": {
    "classification": "INTERESTED"
  }
}
```

## Errors

### 500 — Classification failed

Returned when the email cannot be classified because of a server or processing failure.

```json theme={null}
{
  "success": 0,
  "message": "Something went wrong"
}
```
