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

# API Keys Endpoints

> Route-level reference for MainWP REST API key-management endpoints (list, create, edit, delete) under `/mainwp/v2/rest-api`.

Use these endpoints to manage REST API keys programmatically.

<Note>
  Use the [MainWP Postman collection](https://www.postman.com/mainwp/mainwp/collection/ujfddk4/mainwp-rest-api-v2-current) as the source of truth for request and response schemas.
</Note>

`{key_identifier}` accepts either a numeric key ID (v2) or a `ck_...` key identifier (legacy key format).

## Route Matrix

| Method     | Path                                    | Purpose              | Key Params                                                                                                    |
| ---------- | --------------------------------------- | -------------------- | ------------------------------------------------------------------------------------------------------------- |
| GET        | `/rest-api/keys`                        | List API keys        | `page`, `per_page`                                                                                            |
| POST       | `/rest-api/add-key`                     | Create a new API key | `active` (bool), `permissions` (`read`, `write`, or `read,write`), optional `description`                     |
| PUT, PATCH | `/rest-api/edit-key/{key_identifier}`   | Edit key properties  | `key_identifier`, optional `active`, `permissions` (`read`, `write`, or `read,write`), optional `description` |
| DELETE     | `/rest-api/delete-key/{key_identifier}` | Delete an API key    | `key_identifier`                                                                                              |

`write` maps to the **Write & Delete** permission shown in the MainWP Dashboard UI.

***

## Representative Requests

### Create API key

```bash theme={null}
curl -X POST \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "active": true,
    "permissions": "read,write",
    "description": "Automation key"
  }' \
  "https://your-dashboard.com/wp-json/mainwp/v2/rest-api/add-key"
```

```json theme={null}
{
  "success": 1,
  "message": "API Key created successfully.",
  "token": "GENERATED_TOKEN"
}
```

### Edit API key

```bash theme={null}
curl -X PATCH \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"active": false, "description": "Temporarily disabled"}' \
  "https://your-dashboard.com/wp-json/mainwp/v2/rest-api/edit-key/15"
```

```json theme={null}
{
  "success": 1,
  "message": "API Key updated successfully."
}
```

***

## Related Resources

* [REST API Overview](/api-reference/rest-api/overview)
* [Application Passwords](/api-reference/rest-api/application-passwords)
* [Settings Endpoints](/api-reference/rest-api/settings)
