> ## 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.

# REST API Overview

> MainWP REST API v2 overview, authentication setup, key lifecycle guidance, and endpoint categories for sites, clients, tags, updates, costs, users, settings, monitoring, API keys, posts, pages, and batch operations.

The MainWP REST API lets you manage your MainWP Dashboard programmatically over HTTP.

The API follows REST conventions, returns JSON responses, and is designed for HTTPS requests.

Authentication options:

* Bearer token (recommended for `/mainwp/v2`)
* Consumer Key and Consumer Secret (legacy `/mainwp/v1`)

<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>

<Warning>
  Your MainWP Dashboard URL must be reachable from the system sending API requests. A local-only Dashboard is typically not reachable by external API clients.
</Warning>

## What You'll Learn

* How to authenticate with REST API keys
* How to create v2 API keys and optionally enable v1 compatibility in the UI
* How to manage key permissions and API access state
* Which endpoint category to use for each task
* How long-running update actions return responses

***

## Base URL

All v2 endpoints use:

```text theme={null}
https://your-dashboard.com/wp-json/mainwp/v2/
```

Use Bearer token authentication for v2:

```bash theme={null}
curl -H "Authorization: Bearer YOUR_API_KEY" \
  "https://your-dashboard.com/wp-json/mainwp/v2/sites/basic"
```

***

## Set Up API Keys

<iframe className="w-full aspect-video rounded-xl" src="https://www.youtube.com/embed/soSpRy8ovBo" title="MainWP REST API - Video Tutorial" frameBorder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowFullScreen />

<Steps>
  <Step title="Configure permalinks">
    Go to **WP Admin > Settings > Permalinks** and choose any option except **Plain**.

    <img src="https://mintcdn.com/mainwp/e07i-JbTNXjDT9ia/images/add-ons/c87f79edc47e.jpg?fit=max&auto=format&n=e07i-JbTNXjDT9ia&q=85&s=2834c18fe8be085c4ba3ac70ab301bbe" alt="Permalinks settings" width="787" height="470" data-path="images/add-ons/c87f79edc47e.jpg" />
  </Step>

  <Step title="Create a key in API Access">
    Go to **MainWP Dashboard > API Access > API Keys > Add API Keys** and enter a key name.
  </Step>

  <Step title="Assign permission scope">
    Choose one or more permissions based on the endpoints you plan to call.

    * `Read` for `GET`
    * `Write & Delete` for `POST`, `PUT`, `PATCH`, and `DELETE`
  </Step>

  <Step title="Optional: enable v1 compatibility">
    If your integration requires `/mainwp/v1`, enable **MainWP REST API v1 Compatibility** to generate legacy Consumer Key and Consumer Secret in the same creation flow.

    <img src="https://mintcdn.com/mainwp/ZIVj2Ty_YecTFjto/images/api-reference/rest-api-add-key-v1-compatibility.png?fit=max&auto=format&n=ZIVj2Ty_YecTFjto&q=85&s=bbe7544b526ea51d09180f6b74684372" alt="Add API key with v1 compatibility enabled" width="3798" height="1938" data-path="images/api-reference/rest-api-add-key-v1-compatibility.png" />
  </Step>

  <Step title="Save and store credentials">
    Click **Save Key**, then copy the generated credentials and store them safely.

    <Warning>
      The API key (Bearer token) is shown once and cannot be revealed later. If you enable v1 compatibility, the Consumer Key and Consumer Secret are also shown once.
    </Warning>
  </Step>

  <Step title="Use the token in requests">
    Send it in the `Authorization: Bearer ...` header for all v2 calls.
  </Step>
</Steps>

### Permission Scope

This table reflects v2 permission behavior.

| Permission     | Methods                  | Purpose                              |
| -------------- | ------------------------ | ------------------------------------ |
| Read           | GET                      | Fetch data                           |
| Write & Delete | POST, PUT, PATCH, DELETE | Create, update, and remove resources |

***

## Manage API Access State

MainWP REST API stays active while at least one API key is enabled.

* To disable API access, disable all enabled keys in **MainWP Dashboard > API Access > API Keys**.
* To delete keys, use **Delete** for single keys or bulk delete on the same page.

***

## Endpoint Categories

<CardGroup cols={3}>
  <Card title="Sites" icon="server" href="/api-reference/rest-api/sites">
    Site inventory, sync, plugins, themes, and site operations.
  </Card>

  <Card title="Clients" icon="users" href="/api-reference/rest-api/clients">
    Client CRUD, client fields, and client-level site/cost endpoints.
  </Card>

  <Card title="Tags" icon="tags" href="/api-reference/rest-api/tags">
    Tag CRUD, plus related sites and clients.
  </Card>

  <Card title="Updates" icon="rotate" href="/api-reference/rest-api/updates">
    Update listing, execution, and ignore management.
  </Card>

  <Card title="Costs" icon="dollar-sign" href="/api-reference/rest-api/costs">
    Cost tracker records, linked sites/clients, and batch operations.
  </Card>

  <Card title="Users" icon="user" href="/api-reference/rest-api/users">
    User listing, create/edit/delete, CSV import, and admin password updates.
  </Card>

  <Card title="Settings" icon="sliders" href="/api-reference/rest-api/settings">
    General, advanced, monitoring, email, tools, and other settings domains.
  </Card>

  <Card title="Monitoring" icon="heart-pulse" href="/api-reference/rest-api/monitoring">
    Uptime monitor list, incidents, heartbeat, and monitor settings.
  </Card>

  <Card title="API Keys" icon="key" href="/api-reference/rest-api/api-keys">
    REST API key list, create, edit, and delete endpoints.
  </Card>

  <Card title="Posts" icon="file-pen" href="/api-reference/rest-api/posts">
    Cross-site post listing and post CRUD actions.
  </Card>

  <Card title="Pages" icon="file-lines" href="/api-reference/rest-api/pages">
    Cross-site page listing and page CRUD actions.
  </Card>

  <Card title="Batch" icon="layer-group" href="/api-reference/rest-api/batch">
    Global `/batch` orchestration across multiple controllers.
  </Card>
</CardGroup>

For extension-specific endpoints, see [Extensions Endpoints](/api-reference/rest-api/extensions).

***

## Legacy v1 Compatibility

MainWP still supports legacy v1 endpoints (`/wp-json/mainwp/v1/`) for backward compatibility.

In the UI flow (**MainWP Dashboard > API Access > API Keys > Add API Keys**), you can enable **MainWP REST API v1 Compatibility** to generate legacy Consumer Key and Consumer Secret along with the v2 Bearer token.

The v2 API key endpoints create and manage v2 keys and do not create legacy v1 credentials.

```bash theme={null}
curl -u "CONSUMER_KEY:CONSUMER_SECRET" \
  "https://your-dashboard.com/wp-json/mainwp/v1/sites"
```

Legacy v1 requests can also pass credentials using an `X-Api-Key` header payload that includes `consumer_key` and `consumer_secret`.

<Note>
  Build new integrations on v2 first. Use v1 only where an existing integration still requires it.
</Note>

***

## Batch Update Response Handling

Some update endpoints start background work and return a start or queue confirmation immediately instead of waiting for completion.

```json theme={null}
{
  "success": 1,
  "message": "Batch updates all started successfully.",
  "last_time_start_batch_updates": "2024-09-03T16:57:29"
}
```

Depending on your Dashboard version and execution mode, responses can also include fields such as `job_id` and `queued_count`.

After you receive a start or queued response, wait for the process to finish, then sync your Dashboard or recheck update endpoints.

***

## Related Resources

* [API Keys Endpoints](/api-reference/rest-api/api-keys)
* [Application Passwords](/api-reference/rest-api/application-passwords)
* [MainWP API Introduction](/api-reference/introduction)
