# Creating Access Code CRUD Endpoints

## Overview

Access Codes CRUD endpoints Seam to list access codes created on a door lock.

### Listing Access Codes

After a Door Lock Owner logs in, Seam lists all the access codes programmed and shows them what's been programmed on the door lock. Your Door Locks system should return a JSON list of the access codes on a door lock.

## List all access codes for a lock

<mark style="color:blue;">`GET`</mark> `https://devicecloud.example.com/access_codes?lock_id=<LOCK_ID>`

#### Headers

| Name                                            | Type   | Description             |
| ----------------------------------------------- | ------ | ----------------------- |
| Authorization<mark style="color:red;">\*</mark> | String | Bearer \<access\_token> |

{% tabs %}
{% tab title="200: OK List of Access Codes in JSON" %}

```javascript
{
    "access_codes": [
        {
            "access_code_id": "3043fde0-3c6d-4913-981f-2607f05fe74e",
            "lock_id": "3043fde0-3c6d-4913-981f-2607f05fe74e",
            "owner_id": "3043fde0-3c6d-4913-981f-2607f05fe74e",
            "code": "1234",
            // Optional, but recommended
             "name": "Resident 001 Code"
        },
        {
            "access_code_id": "3043fde0-3c6d-4913-981f-2607f05fe743",
            "lock_id": "3043fde0-3c6d-4913-981f-2607f05fe74e",
            "owner_id": "3043fde0-3c6d-4913-981f-2607f05fe74e",
            "code": "2345",
            // Optional, but recommended
             "name": "Resident 002 Code"
        },
    ]
}
```

{% endtab %}
{% endtabs %}

### Getting an Access Code

Seam may request access code information to display information about an access code to the connecting user.

## Get information about a single access code

<mark style="color:blue;">`GET`</mark> `https://devicecloud.example.com/access_codes/<ACCESS_CODE_ID>`

#### Query Parameters

| Name                                               | Type   | Description                |
| -------------------------------------------------- | ------ | -------------------------- |
| ACCESS\_CODE\_ID<mark style="color:red;">\*</mark> | String | Identifier for Access Code |

#### Headers

| Name                                            | Type   | Description             |
| ----------------------------------------------- | ------ | ----------------------- |
| Authorization<mark style="color:red;">\*</mark> | String | Bearer \<access\_token> |

{% tabs %}
{% tab title="200: OK A single access code JSON object" %}

```javascript
{
  "access_code_id": "3043fde0-3c6d-4913-981f-2607f05fe74e",
  "intercom_id": "3043fde0-3c6d-4913-981f-2607f05fe74e",
  "owner_id": "3043fde0-3c6d-4913-981f-2607f05fe74e",
  "code": "1234",
  // Optional, but recommended
  "name": "Resident 001 Code"
}
```

{% endtab %}
{% endtabs %}

### Removing an Access Code

Seam needs to disable access codes. We need an endpoint to be able to remove an access code.

## Remove an access code

<mark style="color:red;">`DELETE`</mark> `https://devicecloud.example.com/access_codes/<ACCESS_CODE_ID>`

#### Headers

| Name                                            | Type   | Description             |
| ----------------------------------------------- | ------ | ----------------------- |
| Authorization<mark style="color:red;">\*</mark> | String | Bearer \<access\_token> |
| Content-Type<mark style="color:red;">\*</mark>  | String | application/json        |

{% tabs %}
{% tab title="200: OK Access Code successfully removed." %}

```javascript
{
    "ok": true
}
```

{% endtab %}

{% tab title="500: Internal Server Error Something went wrong removing the access code." %}

```javascript
{
    "error_id": "ACCESS_CODE_REMOVAL_FAILED",
    "error_message": "Unexpected Server Error"
}
```

{% endtab %}
{% endtabs %}
