---
updatedAt: 2026-05-27T11:17:14.000Z
agentTools:
  projectIndex: https://developer.unloc.app/llms.txt
---

# Get Keys

Returns Keys for Locks that are part of this Project. Use query parameters to filter the results to a specific App User, Lock or Key state.

- Use the `appUserId` parameter to limit results to Keys for a specific App User.
- Use the `lockId` parameter to limit results to Keys for a specific Lock.
- Use the `excludeStates` parameter to exclude Keys in a specific state. For example, to exclude revoked Keys, use `excludeStates=revoked`.
- Use `excludeSubprojectKeys` to exclude Subproject Keys from the results.

Use the `limit` parameter to specify how many items you want to receive. If not specified, `limit` is set to the maximum supported value of the API: 2500. You can use the `limit` and `startAfterId` query parameters together in order to implement a [pagination system](ref:pagination).

| | |
| --- | --- |
| Required Scope | `project.admin` |


# OpenAPI definition

```json
{
  "openapi": "3.0.3",
  "info": {
    "title": "Unloc API",
    "version": "2.0",
    "description": "The Unloc API allows you to fully manage your Organizations and the belonging Projects.\n\nGetting started:\n\n1. Contact us to make an Organization and API Credentials for you. Make sure to not lose the client id/secret.\n2. Exchange your secret for a JWT using the [OAuth2 Token](ref:gettoken) endpoint.\n3. Create a Project to be managed by the Organization.\n4. Create a Lock Connection for the Project.\n5. Create Keys for your Users.\n\nAll the API endpoints in the Unloc API require a bearer token to be present in the authorization header, with the format authorization: \"Bearer [JWT]\".\n",
    "contact": {
      "name": "Jan Erik",
      "email": "janerik@unloc.app"
    }
  },
  "servers": [
    {
      "url": "https://api.unloc.app",
      "description": "Production server."
    }
  ],
  "tags": [
    {
      "name": "Keys",
      "description": "Key endpoints are used to get, create, and revoke keys to locks in the Project."
    }
  ],
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT"
      }
    }
  },
  "paths": {
    "/v2/projects/{projectId}/keys": {
      "get": {
        "summary": "Get Keys",
        "description": "Returns Keys for Locks that are part of this Project. Use query parameters to filter the results to a specific App User, Lock or Key state.\n\n- Use the `appUserId` parameter to limit results to Keys for a specific App User.\n- Use the `lockId` parameter to limit results to Keys for a specific Lock.\n- Use the `excludeStates` parameter to exclude Keys in a specific state. For example, to exclude revoked Keys, use `excludeStates=revoked`.\n- Use `excludeSubprojectKeys` to exclude Subproject Keys from the results.\n\nUse the `limit` parameter to specify how many items you want to receive. If not specified, `limit` is set to the maximum supported value of the API: 2500. You can use the `limit` and `startAfterId` query parameters together in order to implement a [pagination system](ref:pagination).\n\n| | |\n| --- | --- |\n| Required Scope | `project.admin` |\n",
        "operationId": "getKeys",
        "security": [
          {
            "BearerAuth": [
              "project.admin"
            ]
          }
        ],
        "tags": [
          "Keys"
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid v4"
            },
            "example": "d45031c2-be07-4d20-adbe-4e51e6ad0fed",
            "description": "ID of the Project. Must match the one in the JWT."
          },
          {
            "in": "query",
            "name": "appUserId",
            "required": false,
            "schema": {
              "type": "string",
              "format": "phone-number",
              "pattern": "^\\+?[1-9]\\d{1,14}$"
            },
            "example": "+61452912447",
            "description": "ID of the user. E.164 formatted mobile phone number you want to filter for."
          },
          {
            "in": "query",
            "name": "lockId",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid v4"
            },
            "example": "c0f3aed0-2a7e-4de5-a0ff-3bfc22bfbeef",
            "description": "ID of the Lock you want for filter for."
          },
          {
            "in": "query",
            "name": "excludeSubprojectKeys",
            "explode": false,
            "schema": {
              "type": "boolean"
            },
            "example": false,
            "description": "Should the API call exclude subproject Keys. Defaults to false."
          },
          {
            "in": "query",
            "name": "excludeStates",
            "explode": false,
            "schema": {
              "type": "array",
              "items": {
                "type": "string",
                "enum": [
                  "creating",
                  "scheduled",
                  "active",
                  "inactive",
                  "expired",
                  "revoked",
                  "error"
                ],
                "description": "Available values are:\n  - `creating`: The Key is currently being created with the vendor.\n  - `scheduled`: The Key has been created, and is scheduled to become active in the future.\n  - `active`: The Key is currently usable.\n  - `inactive`: The Key is not currently useable due to recurrence.\n  - `expired`: The Key's _end_ date has passed.\n  - `error`: The Vendor returned an error when attempting to create the Key.\n  - `revoked`: This Key has been explicitly revoked.\n",
                "example": "active"
              }
            },
            "example": [
              "revoked",
              "inactive",
              "error"
            ],
            "description": "Should the API call exclude Keys in the specified states. Defaults to empty array."
          },
          {
            "in": "query",
            "name": "limit",
            "required": false,
            "schema": {
              "type": "number",
              "minimum": 1,
              "maximum": 2500
            },
            "description": "The number of records to return.",
            "example": 150
          },
          {
            "in": "query",
            "name": "startAfterId",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid v4"
            },
            "description": "ID of the record to start retrieving data from. Use together with `limit` for pagination."
          }
        ],
        "responses": {
          "200": {
            "description": "Returns (filtered) Keys for a given Project.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "keys": {
                      "type": "array",
                      "items": {
                        "description": "A Key is an entity used to operate a specific Lock in the Unloc app.\nKeys are assigned to a person, identified via their mobile phone number, and can be time-limited.\nSome Keys are created explicily with the Create Key endpoint. Others are created implicitly by adding a user to a Doorbell or an Access Group.\n",
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "This Key's globally unique ID.",
                            "example": "00003202-3cb2-4ac7-beef-d41668a009bb"
                          },
                          "appUser": {
                            "type": "object",
                            "description": "An App User identifies an Unloc App User via their E.164 formatted mobile phone number.",
                            "properties": {
                              "id": {
                                "type": "string",
                                "format": "phone-number",
                                "description": "E.164 formatted mobile phone number that identifies an Unloc App User.",
                                "example": "+61452912447"
                              },
                              "imageUrl": {
                                "type": "string",
                                "nullable": true,
                                "format": "uri",
                                "description": "Url for this user's profile image. Set by the user via the Unloc app.",
                                "example": "http://www.example.com/image.jpg"
                              },
                              "name": {
                                "type": "string",
                                "description": "The user's name. Set by the user via the Unloc app.",
                                "example": "George Costanza"
                              }
                            },
                            "required": [
                              "id"
                            ]
                          },
                          "lockId": {
                            "type": "string",
                            "format": "uuid v4",
                            "description": "ID of the Lock this Key belongs to.",
                            "example": "19398e97-cef8-4e3e-90a2-43162f319356"
                          },
                          "start": {
                            "type": "string",
                            "format": "date-time",
                            "description": "The date when this Key should become valid. ISO 8601 format in UTC timezone.",
                            "example": "2020-01-28T18:00:00Z"
                          },
                          "end": {
                            "type": "string",
                            "nullable": true,
                            "description": "The date when this Key should expire. ISO 8601 format in UTC timezone. Is null when no expiry is set.",
                            "example": "2020-01-29T20:00:00Z"
                          },
                          "created": {
                            "type": "string",
                            "format": "date-time",
                            "description": "The date when this Key was created. ISO 8601 format in UTC timezone.",
                            "example": "2020-01-29T17:00:00Z"
                          },
                          "subprojectId": {
                            "type": "string",
                            "format": "uuid v4",
                            "description": "If the Key was created as part of a Subproject, this field contains the ID of Subproject this Key belongs to.",
                            "example": "19398e97-cef8-4e3e-90a2-43162f319356"
                          },
                          "accessGroup": {
                            "type": "object",
                            "description": "If the Key was created as part of a Access Group, this field describes the Access Group this Key belongs to.",
                            "properties": {
                              "id": {
                                "type": "string",
                                "format": "uuid v4",
                                "description": "ID of the Access Group this Key belongs to.",
                                "example": "19398e97-cef8-4e3e-90a2-43162f319356"
                              },
                              "name": {
                                "type": "string",
                                "description": "The name of the Access Group this Key belongs to.",
                                "example": "My Access Group"
                              }
                            }
                          },
                          "doorbellUserList": {
                            "type": "object",
                            "description": "If the Key was created as part of a Doorbell, this field describes the DoorbellUserList this Key belongs to.",
                            "properties": {
                              "doorbellId": {
                                "type": "string",
                                "format": "uuid v4",
                                "description": "ID of the Doorbell this Key belongs to.",
                                "example": "19398e97-cef8-4e3e-90a2-43162f319356"
                              },
                              "id": {
                                "type": "string",
                                "format": "uuid v4",
                                "description": "ID of the Doorbell User list this Key belongs to.",
                                "example": "19398e97-cef8-4e3e-90a2-43162f319356"
                              },
                              "name": {
                                "type": "string",
                                "description": "The name of the Doorbell this Key belongs to.",
                                "example": "My Doorbell"
                              }
                            }
                          },
                          "metadata": {
                            "description": "Additional custom data linked to this entity presented in a _key–value_ pairs format. Use this to store additional data that is not part of the core data model.\nUp to 20 _key–value_ pairs are supported. Each  _key_'s length can be up to 40 characters long, and each _value_'s maximum length is 256.\nMetadata Keys with the prefix `unloc` is reserved, and can be overwritten by the system.",
                            "type": "object",
                            "additionalProperties": {
                              "type": "string",
                              "description": "A custom field for you to store additional data."
                            },
                            "example": {
                              "groupId": "abc_123"
                            }
                          },
                          "state": {
                            "type": "string",
                            "enum": [
                              "creating",
                              "scheduled",
                              "active",
                              "inactive",
                              "expired",
                              "revoked",
                              "error"
                            ],
                            "description": "Available values are:\n  - `creating`: The Key is currently being created with the vendor.\n  - `scheduled`: The Key has been created, and is scheduled to become active in the future.\n  - `active`: The Key is currently usable.\n  - `inactive`: The Key is not currently useable due to recurrence.\n  - `expired`: The Key's _end_ date has passed.\n  - `error`: The Vendor returned an error when attempting to create the Key.\n  - `revoked`: This Key has been explicitly revoked.\n",
                            "example": "active"
                          },
                          "recurrence": {
                            "description": "Days of the week when this Key is usable.",
                            "type": "object",
                            "properties": {
                              "timeSpans": {
                                "type": "array",
                                "items": {
                                  "description": "Time period during which this Key is usable on a day of the week.",
                                  "type": "object",
                                  "properties": {
                                    "weekday": {
                                      "type": "string",
                                      "enum": [
                                        "mon",
                                        "tue",
                                        "wed",
                                        "thu",
                                        "fri",
                                        "sat",
                                        "sun"
                                      ]
                                    },
                                    "startHour": {
                                      "type": "integer",
                                      "minimum": 0,
                                      "maximum": 23,
                                      "example": 8
                                    },
                                    "startMinute": {
                                      "type": "integer",
                                      "minimum": 0,
                                      "maximum": 59,
                                      "example": 0
                                    },
                                    "endHour": {
                                      "type": "integer",
                                      "minimum": 0,
                                      "maximum": 23,
                                      "example": 23
                                    },
                                    "endMinute": {
                                      "type": "integer",
                                      "minimum": 0,
                                      "maximum": 59,
                                      "example": 59
                                    }
                                  },
                                  "required": [
                                    "weekday",
                                    "startHour",
                                    "startMinute",
                                    "endHour",
                                    "endMinute"
                                  ]
                                }
                              }
                            }
                          },
                          "category": {
                            "type": "string",
                            "enum": [
                              "projectKey",
                              "accessGroupKey",
                              "installerKey",
                              "sharedKey"
                            ],
                            "description": "Available values are:\n  - `projectKey`: A Key that is created by a Project.\n  - `accessGroupKey`: A Key that is created by adding a User or a Lock to an Access Group.\n  - `installerKey`: A Key that is created by an Installer.\n  - `sharedKey`: A Key that is shared by a User to another User.\n"
                          }
                        },
                        "required": [
                          "id",
                          "appUser",
                          "lockId",
                          "start",
                          "end",
                          "created",
                          "state",
                          "category"
                        ]
                      }
                    },
                    "startAfterId": {
                      "type": "string",
                      "format": "uuid v4",
                      "description": "The ID of the element to query from when using `startAfterId` on the request. Not present when there are no elements left.",
                      "example": "3202afda-ace2-eae7-b33f-e41668a09624"
                    }
                  },
                  "required": [
                    "keys"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Request has missing or invalid parameters.",
            "content": {
              "application/json": {
                "schema": {
                  "description": "Request has missing or invalid parameters.",
                  "properties": {
                    "type": {
                      "type": "string",
                      "description": "URI to the documentation for the error."
                    },
                    "title": {
                      "type": "string",
                      "description": "Human-readable summary of the error."
                    },
                    "detail": {
                      "type": "string",
                      "description": "Human-readable explanation specific to this occurrence of the problem."
                    },
                    "status": {
                      "type": "integer",
                      "example": 400,
                      "description": "HTTP status code for the error."
                    },
                    "traceContext": {
                      "type": "string",
                      "description": "A unique identifier for this error occurrence."
                    },
                    "invalidParams": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "name": {
                            "type": "string",
                            "description": "The name of the invalid parameter.",
                            "example": "lockId"
                          },
                          "reason": {
                            "type": "string",
                            "description": "The reason why the parameter is invalid.",
                            "example": "must have required property 'lockId'"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized request. JWT invalid or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "description": "Unauthorized request. JWT invalid or expired.",
                  "properties": {
                    "error": {
                      "type": "string",
                      "description": "Short identifier for the error.",
                      "example": "JsonWebTokenError"
                    },
                    "errorDescription": {
                      "type": "string",
                      "description": "Verbose description of the error meant for human consumption.",
                      "example": "JWT expired"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
```