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

# Key permissions, expiry and rotation

> Give each API key only what its integration needs, let it expire, and rotate it without downtime.

Every API key carries its own **permissions**, an optional **expiry date** and a record of when it was **last used**. You choose them in the dashboard when you create the key, and you can change the permissions later without changing the secret.

> [!NOTE]
>
> Keys created before permissions existed keep working exactly as before. They hold **full access**: every permission except **Manage keys** (`apiKey:write`), including permissions added in the future. The dashboard shows them as **Acceso total**.

## Creating a key with permissions

1. In the dashboard, go to **Configuraciones** › **Desarrollador** and click **Crear llave**.
2. Name the key after the system that will use it, for example `Tienda en línea` or `ERP`.
3. Choose when it expires: never, 7, 30 or 90 days, or one year.
4. Turn on the permissions it needs. Search by name or by endpoint (`/v1/payment`, `refund`). The panel on the right lists every endpoint the chosen permissions open, each linked to its page in this reference.
5. Click **Crear llave** and copy the key. It is shown only once.

Turning on a permission also turns on what it needs: **Reembolsar pagos** brings **Ver pagos** with it.

### Who can give what

* You can give a key only the permissions your own dashboard role has. A member who cannot see fees cannot make a key that sees fees.
* **Manage keys** (`apiKey:write`) is given only by an owner, signed in as themselves.
* A key that manages keys can create or rotate keys only with permissions it holds itself, and never gives **Manage keys**.

## Permissions

| Permission | In the dashboard | Allows |
| - | - | - |
| `payment:read` | Ver pagos | List and read payments, their status and card |
| `refund:write` | Reembolsar pagos | Refund a payment to the customer's card. Needs `payment:read` |
| `oneTimePayment:read` | Ver cobros únicos | Read one-time payments and whether they were paid |
| `oneTimePayment:write` | Crear y cancelar cobros únicos | Create one-time payments and cancel them. Needs `oneTimePayment:read` |
| `paymentLink:read` | Ver links de pago | Read payment links and their products |
| `subscription:read` | Ver suscripciones | Read subscriptions and their charges |
| `paymentMethod:read` | Ver tarjetas guardadas | Read saved cards, without charging them |
| `paymentMethod:write` | Guardar y cobrar tarjetas | Save cards, charge them, hold and release amounts, revoke them. Needs `paymentMethod:read` |
| `paymentIntent:read` | Ver cobros en terminal | Read payment intents sent to a terminal |
| `paymentIntent:write` | Enviar cobros a terminales | Send a payment intent to a terminal and cancel it. Needs `paymentIntent:read` and `terminal:read` |
| `terminal:read` | Ver terminales | Read the organization's terminals |
| `salesperson:read` | Ver vendedores | Read salespeople and their branches |
| `product:read` | Ver productos | Read products and prices |
| `promotion:read` | Ver promociones | Read the installment promotions in force |
| `fee:read` | Ver comisiones | See the fee of each payment. Without it, `fee` is `null` |
| `payout:read` | Ver depósitos | Read the payouts to your bank accounts |
| `bankAccount:read` | Ver cuentas para depósitos | Read the accounts a charge can be deposited in |
| `organization:read` | Ver la organización | Read your organization's name, RFC and address |
| `member:read` | Ver el equipo | Read your team members, their e-mail and role |
| `apiKey:write` | Administrar llaves | Create, rotate and revoke keys through the API. Owner only |

The same permissions apply to the payment-acceptance endpoints (`/api/one-time-payment`, `/api/payment-intent`, `/api/payment-method`): a key without `paymentMethod:write` cannot charge a saved card there either.

> [!TIP]
>
> Ask a key what it holds with [`GET /developer/v1/api-key/current`](https://docs.compago.com/api-reference/developer/api-key/current). Any key may call it.

## Expiry and last use

A key with an expiry date stops working at that moment and answers `401` with `API_KEY_EXPIRED`. It stays on the dashboard list as **Vencida**, so you can see what stopped and rotate it.

The list also shows when each key was last used, to the minute. A key nobody has used in months is a key you can revoke.

## Rotating a key without downtime

Rotating creates a new secret for the same key: same name, same permissions, same lifetime counted from the rotation. The current secret keeps working for an overlap you choose (now, 1 hour, 24 hours or 7 days, 24 hours by default), so you can deploy the new one before the old one stops.

**1. Rotate**

In the dashboard, open the key's **⋯** menu and choose **Rotar llave**, or call [`POST /developer/v1/api-key/{id}/roll`](https://docs.compago.com/api-reference/developer/api-key/roll) with a key that holds `apiKey:write`.

```bash theme={null}
curl -X POST https://api-harmony.compago.com/api/developer/v1/api-key/$KEY_ID/roll \
  -H "x-api-key: $COMPAGO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"expireCurrentIn": 86400}'
```

**2. Deploy the new secret**

Store the `key` from the response in your secrets manager and deploy. `previous.expiresAt` says until when the old secret works.

**3. Let the old one expire**

Nothing else to do. Once the overlap ends, the old secret answers `API_KEY_EXPIRED`.

A key can rotate itself, which lets an integration rotate on its own schedule. A key that was already rotated cannot be rotated again (`409 API_KEY_ALREADY_ROLLED`): rotate its replacement instead.

## Key format

Keys created from now on start with `cmp_` followed by 64 letters and digits. The dashboard shows the first eight characters and the last four, enough to tell which key a system uses. Older keys keep their format and keep working.

Compago stores only a hash of each key. Nobody, including Compago, can show a key again after it was created or rotated.

## Owner notifications

Every owner of the organization gets an e-mail when a key is created, rotated or revoked, saying who did it. Each of these changes is also recorded in **Configuraciones** › **Actividad**.

## Errors

| Status | Code | Meaning |
| - | - | - |
| `401` | `UNAUTHORIZED` | The key is missing or does not exist |
| `401` | `API_KEY_EXPIRED` | The key reached its expiry date, or the overlap of a rotation ended |
| `401` | `API_KEY_DISABLED` | The key was turned off in the dashboard. It can be turned on again |
| `401` | `API_KEY_REVOKED` | The key was revoked. It never works again |
| `403` | `INSUFFICIENT_SCOPE` | The key does not hold the permission this endpoint needs |
| `403` | `SCOPE_NOT_GRANTABLE` | The key tried to create or rotate a key with permissions it does not hold |
| `409` | `API_KEY_ALREADY_ROLLED` | The key was already rotated. Rotate its replacement |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.