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

# Costs Endpoints

> Route-level reference for MainWP REST API v2 Cost Tracker endpoints, including cost CRUD, related sites/clients lookups, and cost batch operations.

Use these endpoints to manage Cost Tracker entries in MainWP Dashboard.

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

<Note>
  Cost endpoints require the built-in [Cost Tracker](/clients/cost-tracker) module to be enabled.
</Note>

## Route Matrix

| Method           | Path                  | Purpose                         | Key Params                                                                                         |
| ---------------- | --------------------- | ------------------------------- | -------------------------------------------------------------------------------------------------- |
| GET              | `/costs`              | List costs                      | `page`, `per_page`, `search`, `include`, `exclude`, `status`, `category`, `type`                   |
| POST, PUT, PATCH | `/costs/add`          | Create a cost                   | `name`, `price`, `payment_type`, `product_type`, `renewal_type`, one of `sites`/`groups`/`clients` |
| GET              | `/costs/{id}`         | Get one cost                    | `id`                                                                                               |
| POST, PUT, PATCH | `/costs/{id}/edit`    | Edit a cost                     | Same fields as add                                                                                 |
| DELETE           | `/costs/{id}/remove`  | Remove a cost                   | `id`                                                                                               |
| GET              | `/costs/{id}/sites`   | List sites linked to a cost     | `id`                                                                                               |
| GET              | `/costs/{id}/clients` | List clients linked to a cost   | `id`                                                                                               |
| POST             | `/costs/batch`        | Batch cost create/update/delete | `create[]`, `update[]`, `delete[]`                                                                 |

***

## Key Request Fields

Common write fields (create/edit):

* `name`, `price`, `payment_type`, `license_type`, `product_type`, `product_slug`
* `renewal_type`, `last_renewal`, `payment_method`, `cost_tracker_status`
* `url`, `note`, visual fields like `product_color`, `icon_hidden`
* Relationship selectors: `sites[]`, `groups[]`, or `clients[]`

At least one target set (`sites`, `groups`, or `clients`) is required.

***

## Representative Requests

### Create a cost

```bash theme={null}
curl -X POST \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name":"Hosting Plan",
    "price":49.00,
    "payment_type":"subscription",
    "product_type":"hosting",
    "renewal_type":"monthly",
    "sites":[12]
  }' \
  "https://your-dashboard.com/wp-json/mainwp/v2/costs/add"
```

```json theme={null}
{
  "success": 1,
  "data": {
    "id": 22,
    "name": "Hosting Plan"
  }
}
```

### Remove a cost

```bash theme={null}
curl -X DELETE \
  -H "Authorization: Bearer YOUR_API_KEY" \
  "https://your-dashboard.com/wp-json/mainwp/v2/costs/22/remove"
```

```json theme={null}
{
  "success": 1,
  "message": "Cost deleted successfully."
}
```

***

## Related Resources

* [REST API Overview](/api-reference/rest-api/overview)
* [Clients Endpoints](/api-reference/rest-api/clients)
* [Sites Endpoints](/api-reference/rest-api/sites)
* [Batch Endpoint](/api-reference/rest-api/batch)
