# API Tokens

## Managing Tokens

Details of how the `tokens` endpoint can be used to retrieve, create, and revoke API tokens in the parcelLab system are described below.

{% hint style="info" %}
All endpoints require a token with `generate` scope.
{% endhint %}

<details>

<summary><mark style="color:blue;">GET</mark> List of All Tokens</summary>

You can retrieve a list of all API tokens with the `tokens/list` endpoint. To use this API, you need your parcelLab `user_id` and `API token` for authentication.

The details of the Get List of All Tokens API are described in the following section.

**API Details**

<mark style="color:blue;">`GET`</mark> `https://api.parcellab.com/tokens/list`

**Header**

| Name         | Type   | Description         |
| ------------ | ------ | ------------------- |
| user         | number | parcelLab user ID   |
| token        | string | parcelLab API token |
| content-type | string | 'application/json'  |

An example request is displayed below to show the format for retrieving the list of tokens.

```bash
curl --location 'https://api.parcellab.com/tokens/list’ \
  --header 'content-type: application/json' \
  --header 'user: 100' \
  --header 'token: parcelLabAPItoken-30characters' \
```

**Responses**

* 200 - accepted

</details>

<details>

<summary><mark style="color:green;">POST</mark> Create a New Token</summary>

You can create a new API token with the `tokens/generate` endpoint. To use this API, you need your parcelLab `user_id` and `API token` for authentication. When you have generated a new API token, this can be used for authentication with the parcelLab API.

The details of the Create a New Token API are described in the following section.

**API Details**

<mark style="color:green;">`POST`</mark> `https://api.parcellab.com/tokens/generate`

**Header**

| Name         | Type   | Description         |
| ------------ | ------ | ------------------- |
| user         | number | parcelLab user ID   |
| token        | string | parcelLab API token |
| content-type | string | 'application/json'  |

**Request Body**

| Name  | Type   | Description                                            |
| ----- | ------ | ------------------------------------------------------ |
| note  | string | An associated note, which can be any string.           |
| scope | string | The scope can be one of `read`, `write` or `generate`. |

An example request is displayed below to show the format for creating a token.

```bash
curl --location 'https://api.parcellab.com/tokens/generate’ \
  --header 'content-type: application/json' \
  --header 'user: 100' \
  --header 'token: parcelLabAPItoken-30characters' \
  --data ‘{
       “note”: “track”,
       “scopes”: [
            “write”
       ]
}’
```

**Responses**

* 200 - accepted

</details>

<details>

<summary><mark style="color:green;">POST</mark> Revoke a Token</summary>

You can revoke a single API token with the `tokens/revoke` endpoint. To use this API, you need your parcelLab `user_id` and `API token` for authentication.

This action revokes the token immediately.

The details of the Revoke a Token API are described in the following section.

**API Details**

<mark style="color:green;">`POST`</mark> `https://api.parcellab.com/tokens/revoke`

**Header**

| Name         | Type   | Description         |
| ------------ | ------ | ------------------- |
| user         | number | parcelLab user ID   |
| token        | string | parcelLab API token |
| content-type | string | 'application/json'  |

**Request Body**

| Name    | Type   | Description                                  |
| ------- | ------ | -------------------------------------------- |
| tokenId | number | The token ID as specified in `/tokens/list`. |

An example request is displayed below to show the format for revoking a token.

```bash
curl --location 'https://api.parcellab.com/tokens/revoke’ \
  --header 'content-type: application/json' \
  --header 'user: 100' \
  --header 'token: parcelLabAPItoken-30characters' \
  --data ‘{
       “tokenId”: “The token ID as in /tokens/list”
}’
```

**Responses**

* 200 - accepted

</details>


---

# Agent Instructions: 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:

```
GET https://docs.parcellab.com/docs/developers/v2/api-access/tokens.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
