---
title: "Authentication and scopes"
description: "How UserLoop API keys work, what each scope allows, and what happens when a key expires, is revoked or its creator leaves."
---

> Documentation Index
> Fetch the complete documentation index at: https://docs.userloop.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Authentication and scopes

Your own API requests carry an API key. Zapier uses its own OAuth connection instead; see [Zapier](https://docs.userloop.io/surveys/integrations/zapier/). A key belongs to the person who created it, in one organisation, and does what they chose for it: its scopes. It stops working when it is revoked, when it expires, or when that person leaves the organisation.

> **Plus plan**
>
> The API is part of the Plus plan. If the organisation moves to another plan, its keys are kept but every endpoint except `GET /me` answers `402` until it moves back.

## Send the key

Send the key in the `Authorization` header as a bearer token, on every request:

```bash
curl -s https://app.userloop.io/api/v1/me \
  -H "Authorization: Bearer ulk_live_…"
```

The API reads the key from that header only.

- A key in the address, such as `?api_key=` or `?key=`, is refused with `400` `key_in_query` and never used. Revoke that key: addresses end up in logs.
- Browsers can't call the API. It sends no CORS headers, so a web page can't make a request with a key. Call it from your server.
- `GET /openapi.json` and `GET /problems/{code}` need no key.

## What a key looks like

| Starts with | What it is |
| --- | --- |
| `ulk_live_` | A key for UserLoop. Every key you create at app.userloop.io starts this way. |
| `ulk_test_` | A key from a UserLoop test environment. It doesn't work at app.userloop.io. |
| `ul_live_` or `ul_test_` | A key of UserLoop's old API. This API refuses it with `401` `legacy_key`; create a new key instead. See [Move from the old API](https://docs.userloop.io/developers/api/move-from-the-old-api/). |

A key is 55 characters: the prefix, 40 random letters and digits, and a 6-character checksum. The API checks the checksum before it looks the key up, so a key that lost characters when it was copied gets `401` `unauthenticated` straight away. Secret scanners can recognise it the same way.

UserLoop stores only a hash of the key and shows the key once, when it is created. Afterwards the API keys page and `GET /me` show only its hint, the first and last four characters: `ulk_live_4Qm7…C2d3`.

## Scopes

A key's scopes are the **Permissions** ticked when it was created. The read scopes are ticked to start with.

| Scope | On the API keys page | What it allows |
| --- | --- | --- |
| `surveys:read` | **Read surveys** | List and read surveys and their questions (`GET /surveys`, `GET /surveys/{survey_id}`), sites (`GET /sites`), and exports and PDF reports (`GET /exports`, `GET /reports/pdf`). |
| `surveys:write` | **Edit surveys** | Create and change surveys and questions, publish, unpublish, archive and restore surveys, and send survey emails (`POST /surveys/{survey_id}/send` or `POST /sends`). |
| `responses:read` | **Read responses** | Read responses, written answers, customers, analytics and themes; download export and PDF files; list webhooks and their sample events. |
| `responses:write` | **Add responses** | Record a new response to a live link, email or website survey (`POST /responses`). |
| `reports:write` | **Manage reports** | Request exports and PDF reports, and add, test and remove webhooks. |
| `account:read` | **Read account** | Read the organisation, its plan and its usage (`GET /account`, `GET /usage`). |
| `account:write` | **Change settings** | Offered to organisation admins only. No v1 endpoint uses it yet. |

`GET /me` needs no scope. The [API reference](https://docs.userloop.io/developers/api/reference/) gives the scope of every endpoint, as `x-userloop-scope` in the OpenAPI description.

A request to an endpoint whose scope the key doesn't have gets `403` `insufficient_scope`, with the missing scope in `required_scope`:

```json
{
  "type": "https://app.userloop.io/api/v1/problems/insufficient_scope",
  "title": "Insufficient scope",
  "status": 403,
  "detail": "This API key doesn't have the surveys:write scope. Create a key with it on the API keys page.",
  "instance": "req_3Kp9WnX1cV5bM7qL",
  "code": "insufficient_scope",
  "required_scope": "surveys:write"
}
```

A key's scopes can't be changed after it is created. To give an app more, create a new key and revoke the old one.

Some actions need more than a scope:

- **Publish, unpublish, archive and restore a survey** need `surveys:write` and a key created by an organisation admin. A member's key gets `403` `forbidden`.
- **A webhook for response events** needs `reports:write` to create it and `responses:read` too, so it never delivers more than the key could read.
- **Customers' contact details** need a key created with **Include customers’ contact details when asked**. See [Customer contact details in responses](https://docs.userloop.io/developers/api/contact-details/).

## The key acts as the person who created it

Everything a key does is done as its creator: it shows as them in UserLoop, and their role in the organisation limits it.

- **Who can create a key:** any member, for themselves. A member can tick every scope except **Change settings**; an organisation admin can tick all seven.
- **When their role changes,** the key changes with it. UserLoop checks the creator's role at least every 15 minutes, and a key can only use the scopes the creator's current role allows. `key.scopes` in `GET /me` shows what the key can do now.
- **When the creator leaves the organisation,** their keys stop working within 15 minutes and answer `401` `key_suspended`. The API keys page shows them as **Stopped**, with "*name* left the organisation". A stopped key can't be turned back on: a current member creates a new key.

Keys can only be created on the API keys page, by someone signed in. A key can't create another key.

## Expiry

When you create a key, choose under **Expires**: **30 days**, **90 days**, **1 year** (chosen to start with) or **Never**. The date shows in the **Expires** column on the API keys page and as `key.expires_at` in `GET /me` (`null` for never).

After that date, the key answers `401` `key_expired`. An expired key can't be renewed: create a new one before the old one expires, move your app to it, and revoke the old one.

## Who sees and manages keys

- A member sees their own keys on the API keys page. An organisation admin sees every key in the organisation.
- A key's creator or an organisation admin can rename it (the key keeps working) or revoke it.
- An organisation can have up to 25 active keys. At 25, **Create key** is turned off with "25 active keys is the most. Revoke one to add another." A member, who sees only their own keys, may instead get "An organisation can have up to 25 active API keys." when they create one.

## Revoke a key

On the API keys page, select **Revoke** on the key's row, then **Revoke key**. The key answers `401` `key_revoked` within a minute. A revoked key can't be turned back on.

Revoke a key when the app that used it is retired, when it may have leaked (pasted in a chat, committed to a repository, sent in an address), or when you replace it with a new one.

## Errors from authentication

| Status and code | Why |
| --- | --- |
| `400` `key_in_query` | The key was in the address, not the `Authorization` header. |
| `401` `unauthenticated` | No key, a key that isn't well formed, or a key UserLoop doesn't know. |
| `401` `legacy_key` | A `ul_live_` or `ul_test_` key of the old API. |
| `401` `key_revoked` | The key was revoked. |
| `401` `key_expired` | The key passed its expiry date. |
| `401` `key_suspended` | The person who created the key left the organisation. |
| `402` `plan_required` | The organisation's plan doesn't include the API. |
| `403` `insufficient_scope` | The key doesn't have the scope the endpoint needs. |
| `403` `forbidden` | The creator's role doesn't allow the action, for example publishing as a member. |

Every `401` also carries `WWW-Authenticate: Bearer realm="UserLoop API", error="invalid_token"`. [Errors](https://docs.userloop.io/developers/api/errors/) lists every code.

## Related

- [Quickstart: get a key and make a call](https://docs.userloop.io/developers/api/quickstart/)
- [Customer contact details in responses](https://docs.userloop.io/developers/api/contact-details/)
- [Rate limits and safe retries](https://docs.userloop.io/developers/api/rate-limits-and-retries/)

Source: https://docs.userloop.io/developers/api/authentication/index.mdx
