> For the complete documentation index, see [llms.txt](https://docs.tokensource.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tokensource.com/objectives.md).

# Objectives

**Base Path:** \`/v1/objectives

## Create Objective

**Method:** `POST`\
**Endpoint:** `https://api.tokensource.com/v1/objectives`\
**Description:** Creates a new objective.

**Request Body:**

```json
{
  "name": "New Objective",
  "description": "Description of the objective",
  "status": "on_track",
  "metrics": [
    { "key": "metric1", "value": "value1" },
    { "key": "metric2", "value": "value2" }
  ]
}
```

**Response (201 Created):**

```json
{
  "message": "Objective created",
  "objective": {
    "id": 1,
    "externalId": "generated-external-id",
    "name": "New Objective",
    "description": "Description of the objective",
    "status": "on_track",
    "userId": 1,
    "createdAt": "2023-10-27T13:00:00Z",
    "updatedAt": "2023-10-27T13:00:00Z",
    "metrics": [
      {
        "id": 1,
        "objectiveId": 1,
        "value": "{\"key\":\"metric1\",\"value\":\"value1\"}",
        "createdAt": "2023-10-27T13:00:00Z"
      }
    ],
    "aiAssistants": []
  }
}
```

## Get All Objectives

**Method:** `GET`\
**Endpoint:** `https://api.tokensource.com/v1/objectives`\
**Description:** Retrieves all objectives.

**Response (200 OK):**

```json
[
  {
    "id": 1,
    "externalId": "external-id-1",
    "name": "Objective 1",
    "description": "Description 1",
    "status": "on_track",
    "userId": 1,
    "createdAt": "2023-10-26T10:00:00Z",
    "updatedAt": "2023-10-27T09:00:00Z",
    "metrics": [
      {
        "id": 1,
        "objectiveId": 1,
        "value": "{\"key\":\"metric1\",\"value\":\"value1\"}",
        "createdAt": "2023-10-26T10:00:00Z"
      }
    ],
    "aiAssistants": [
      { "id": 1, "name": "Assistant A" }
    ]
  }
]
```

## Get Objective by ID

**Method:** `GET`\
**Endpoint:** `https://api.tokensource.com/v1/objectives/{id}`\
**Description:** Retrieves a specific objective by its external ID.

**Parameters:**

* `id` (string, required)

**Response (200 OK):**

```json
{
  "id": 2,
  "externalId": "external-id-2",
  "name": "Objective 2",
  "description": "Description 2",
  "status": "needs_attention",
  "userId": 1,
  "createdAt": "2023-10-25T14:30:00Z",
  "updatedAt": "2023-10-26T16:00:00Z",
  "metrics": [],
  "aiAssistants": []
}
```

**Response (404 Not Found):**

```json
{
  "error": "Objective not found"
}
```

## Update Objective

**Method:** `PUT`\
**Endpoint:** `https://api.tokensource.com/v1/objectives/{id}`\
**Description:** Updates an existing objective.

**Parameters:**

* `id` (integer, required)

**Request Body:**

```json
{
  "name": "Updated Objective Name",
  "description": "Updated description",
  "status": "completed",
  "metrics": [
    { "key": "metric1", "value": "updated value1" }
  ],
  "aiAssistantId": 2
}
```

**Response (200 OK):**

```json
{
  "message": "Objective updated",
  "objective": {
    "id": 2,
    "externalId": "external-id-2",
    "name": "Updated Objective Name",
    "description": "Updated description",
    "status": "completed",
    "userId": 1,
    "createdAt": "2023-10-25T14:30:00Z",
    "updatedAt": "2023-10-27T14:00:00Z",
    "metrics": [
      {
        "id": 2,
        "objectiveId": 2,
        "value": "{\"key\":\"metric1\",\"value\":\"updated value1\"}",
        "createdAt": "2023-10-27T14:00:00Z"
      }
    ],
    "aiAssistants": [
      { "id": 2, "name": "Assistant B" }
    ]
  }
}
```

## Delete Objective

**Method:** `DELETE`\
**Endpoint:** `https://api.tokensource.com/v1/objectives/{id}`\
**Description:** Deletes an objective.

**Parameters:**

* `id` (integer, required)

**Response (200 OK):**

```json
{
  "message": "Objective deleted"
}
```

\`


---

# 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.tokensource.com/objectives.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.
