# Set Active Agent

This section provides instructions on using the /project/active-agent endpoint to set active agent for .

**Step1: Prepare Your Request**

* **Endpoint:** `/project/active-agent`
* **Method:** `PATCH`
* **URL:** `https://api.talkstackai.com/project/active-agent`
* **Headers:** Include `Content-Type: application/json`.
* **Authorization:** Bearer token or x-api-key in Headers

**Step2: Create the Request Body**

* `projectId`: Id of the project.
* `active_agent`: Id of the agent you want to set as active.

```json
{
    "projectId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "active_agent": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
```

**Step 3: Send the Request**

Use your preferred HTTP client to send the PATCH request with the JSON body.

**Step 4: Handle the request**

**Success Response:**

* **Status Code:** `200 OK`
* **Body:**

```json
{
    "message": "updated active agent successfully.",
    "status": "success",
    "project": {
          "name": "John Smith Clinic",
          "description": projectData.description,
          "active_agent": projectData.active_agent,
          "created_at": projectData.created_at,
          "call_status_webhook": projectData.call_status_webhook,
          "user_id": projectData.user_id,
     }
}
```

**Troubleshooting**

* `400 Bad Request`: If the `projectId` and `active_agent` are not in the request body.
* `401 Unauthorized`: If the user is unauthorized or the token is missing.
* `500 Internal Server Error`: For errors while setting active agent.
