> For the complete documentation index, see [llms.txt](https://docs.sensecrypt.com/opencv-face-recognition-server/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sensecrypt.com/opencv-face-recognition-server/publish-your-docs/collection-management.md).

# Collection Management

Before performing Face Search (1:N, N:N), you first need to create a collection and enroll the persons in a specific collection.&#x20;

Each collection is a table, collection name should be unique, it’s not allowed to create two collections with the same name. &#x20;

Upon a collection being created, the collection name is not allowed to change. you can delete a collection, in this case, all enrolled persons within the collection will be deleted as well, so please be careful.&#x20;

## Create collection

<mark style="color:green;">`POST`</mark> `/collection`

This endpoint is to create a collection

**Headers**

| Name         | Value              |
| ------------ | ------------------ |
| Content-Type | `application/json` |
| x-api-key    | `<your-api-key>`   |

**Body**

<table><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><code>name</code></td><td><p>Required: Yes </p><p>Type: string</p><p>Example: </p><pre class="language-json"><code class="lang-json">"name": "MyCollection"
</code></pre><p>Each collection is like a table, the name of the collection is the unique identifier. </p><p>Once created, no modification of the name is allowed.</p></td></tr></tbody></table>

**Response**

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

```json
{
  "name": "MyCollection",
  "num_persons": 0
}
```

{% endtab %}

{% tab title="400" %}

```json
{
  "code": "ERR_INVALID_COLLECTION_NAME",
  "message": "Collection names can only contain alphanumeric characters, underscores, hyphens, and periods."
}
```

{% endtab %}

{% tab title="401" %}

```json
{
  "code": "ERR_API_KEY_NOT_PRESENT",
  "message": "The API key is missing from the request."
}
```

{% endtab %}

{% tab title="403" %}

```json
{
  "code": "ERR_API_KEY_NOT_VALID",
  "message": "The API key is not valid."
}
```

{% endtab %}

{% tab title="409" %}

```json
{
  "code": "ERR_ALREADY_EXISTS",
  "message": "Another entity already exists with the same ID."
}
```

{% endtab %}

{% tab title="500" %}

```json
{
  "code": "ERR_DATABASE_ERROR",
  "message": "An error occurred while connecting with the database, please retry your request later."
}
```

{% endtab %}
{% endtabs %}

## Delete a collection

<mark style="color:orange;">`DELETE`</mark> `/collection`

This endpoint is to delete a collection.

**Headers**

| Name         | Value              |
| ------------ | ------------------ |
| Content-Type | `application/json` |
| x-api-key    | `<your-api-key>`   |

**Body**

<table><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><code>name</code></td><td><p>Required: Yes </p><p>Type: string</p><p>Example: </p><pre class="language-json"><code class="lang-json">"name": "MyCollection"
</code></pre><p>Each collection is like a table, upon deletion of a collection, all enrolled person within the collection will be deleted.</p></td></tr></tbody></table>

**Response**

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

```json
{
   "name": "MyCollection",
   "num_persons": 0
}
```

{% endtab %}

{% tab title="400" %}

```json
{
  "code": "ERR_INVALID_COLLECTION_NAME",
  "message": "Collection names can only contain alphanumeric characters, underscores, hyphens, and periods."
}
```

{% endtab %}

{% tab title="401" %}

```json
{
  "code": "ERR_API_KEY_NOT_PRESENT",
  "message": "The API key is missing from the request."
}
```

{% endtab %}

{% tab title="403" %}

```json
{
  "code": "ERR_API_KEY_NOT_VALID",
  "message": "The API key is not valid."
}
```

{% endtab %}

{% tab title="404" %}

```json
{
  "code": "ERR_NOT_FOUND",
  "message": "The requested entity could not be found."
}
```

{% endtab %}

{% tab title="500" %}

```json
{
  "code": "ERR_DATABASE_ERROR",
  "message": "An error occurred while connecting with the database, please retry your request later."
}
```

{% endtab %}
{% endtabs %}
