# The BotSubscription API

> BotSubscription REST API documentation - authentication, response format, and common patterns

Source: https://docs.botsubscription.com/api/overview/

This REST API provides endpoints for managing projects, users, subscriptions, payments, and related resources. All endpoints require authentication unless explicitly specified otherwise.

## Quick reference

<ApiQuickRef>
  <ApiQuickGroup title="Users">
    <ApiQuickItem method="GET"    path="/v2/projects/{project_id}/users"                href="https://docs.botsubscription.com/api/users/list/"     label="List" />
    <ApiQuickItem method="GET"    path="/v2/projects/{project_id}/users/search"         href="https://docs.botsubscription.com/api/users/search/"   label="Search" />
    <ApiQuickItem method="GET"    path="/v2/projects/{project_id}/users/{user_id}"      href="https://docs.botsubscription.com/api/users/get/"      label="Retrieve" />
    <ApiQuickItem method="PUT"    path="/v2/projects/{project_id}/ban/{user_id}"        href="https://docs.botsubscription.com/api/users/ban/"      label="Ban" />
    <ApiQuickItem method="DELETE" path="/v2/projects/{project_id}/ban/{user_id}"        href="https://docs.botsubscription.com/api/users/unban/"    label="Unban" />
  </ApiQuickGroup>

  <ApiQuickGroup title="Plans">
    <ApiQuickItem method="GET"    path="/v2/projects/{project_id}/plans"                href="https://docs.botsubscription.com/api/plans/list/"     label="List" />
    <ApiQuickItem method="GET"    path="/v2/projects/{project_id}/plans/{plan_id}"      href="https://docs.botsubscription.com/api/plans/get/"      label="Retrieve" />
    <ApiQuickItem method="POST"   path="/v2/projects/{project_id}/plans"                href="https://docs.botsubscription.com/api/plans/create/"   label="Create" />
    <ApiQuickItem method="PATCH"  path="/v2/projects/{project_id}/plans/{plan_id}"      href="https://docs.botsubscription.com/api/plans/update/"   label="Update" />
    <ApiQuickItem method="DELETE" path="/v2/projects/{project_id}/plans/{plan_id}"      href="https://docs.botsubscription.com/api/plans/delete/"   label="Delete" />
  </ApiQuickGroup>

  <ApiQuickGroup title="Memberships">
    <ApiQuickItem method="GET"    path="/v2/projects/{project_id}/memberships"                       href="https://docs.botsubscription.com/api/memberships/list/"        label="List" />
    <ApiQuickItem method="PATCH"  path="/v2/projects/{project_id}/memberships/extend"               href="https://docs.botsubscription.com/api/memberships/extend/"      label="Extend selected or all" />
    <ApiQuickItem method="PATCH"  path="/v2/projects/{project_id}/memberships/{user_id}/extend"     href="https://docs.botsubscription.com/api/memberships/extend-user/" label="Extend a user" />
    <ApiQuickItem method="DELETE" path="/v2/projects/{project_id}/memberships/{membership_id}"      href="https://docs.botsubscription.com/api/memberships/delete/"      label="Delete" />
  </ApiQuickGroup>

  <ApiQuickGroup title="Access Tokens">
    <ApiQuickItem method="POST" path="/v2/projects/{project_id}/access-tokens" href="https://docs.botsubscription.com/api/access-tokens/prepare/" label="Prepare" />
    <ApiQuickItem method="POST" path="/v2/projects/{project_id}/access-tokens/activate" href="https://docs.botsubscription.com/api/access-tokens/activate/" label="Activate" />
    <ApiQuickItem method="GET" path="/v2/projects/{project_id}/access-tokens" href="https://docs.botsubscription.com/api/access-tokens/list/" label="List" />
    <ApiQuickItem method="GET" path="/v2/projects/{project_id}/access-tokens/eligibility" href="https://docs.botsubscription.com/api/access-tokens/eligibility/" label="Eligibility" />
    <ApiQuickItem method="DELETE" path="/v2/projects/{project_id}/access-tokens/{access_token_id}" href="https://docs.botsubscription.com/api/access-tokens/revoke/" label="Revoke" />
    <ApiQuickItem method="POST" path="/v2/projects/{project_id}/access-tokens/redeem" href="https://docs.botsubscription.com/api/access-tokens/redeem/" label="Redeem for member" />
  </ApiQuickGroup>

  <ApiQuickGroup title="Merchant Accounts">
    <ApiQuickItem method="POST" path="/v2/projects/{project_id}/merchant-accounts/{merchant_account_id}/verify-webhook" href="https://docs.botsubscription.com/api/merchant-accounts/verify-webhook/" label="Verify provider webhook" />
  </ApiQuickGroup>

  <ApiQuickGroup title="Integrations">
    <ApiQuickItem method="GET"    path="/v2/projects/{project_id}/integrations/api-keys/scopes"     href="https://docs.botsubscription.com/api/integrations/list-scopes/"     label="Discover scopes" />
    <ApiQuickItem method="GET"    path="/v2/projects/{project_id}/integrations/webhooks"            href="https://docs.botsubscription.com/api/integrations/list-webhooks/"   label="List webhooks" />
    <ApiQuickItem method="POST"   path="/v2/projects/{project_id}/integrations/webhooks"            href="https://docs.botsubscription.com/api/integrations/create-webhook/"  label="Create webhook" />
  </ApiQuickGroup>

  <ApiQuickGroup title="Coupons">
    <ApiQuickItem method="GET"    path="/v2/projects/{project_id}/coupons"             href="https://docs.botsubscription.com/api/coupons/list/"      label="List" />
    <ApiQuickItem method="POST"   path="/v2/projects/{project_id}/coupons"             href="https://docs.botsubscription.com/api/coupons/create/"    label="Create" />
    <ApiQuickItem method="POST"   path="/v2/projects/{project_id}/coupons/validate"    href="https://docs.botsubscription.com/api/coupons/validate/"  label="Validate" />
  </ApiQuickGroup>

  <ApiQuickGroup title="Documents">
    <ApiQuickItem method="GET" path="/v2/projects/{project_id}/documents" href="https://docs.botsubscription.com/api/documents/list/" label="List documents" />
    <ApiQuickItem method="GET" path="/v2/projects/{project_id}/documents/{document_id}" href="https://docs.botsubscription.com/api/documents/get/" label="Retrieve document" />
    <ApiQuickItem method="GET" path="/v2/projects/{project_id}/documents/{document_id}/download" href="https://docs.botsubscription.com/api/documents/download/" label="Download metadata" />

  </ApiQuickGroup>
  <ApiQuickGroup title="Analytics">
    <ApiQuickItem method="GET" path="/v2/projects/{project_id}/analytics/renewals/calendar" href="https://docs.botsubscription.com/api/analytics/renewals-calendar/" label="Renewal calendar" />
    <ApiQuickItem method="GET" path="/v2/projects/{project_id}/analytics/overview" href="https://docs.botsubscription.com/api/analytics/overview/" label="Analytics Summary" />
    <ApiQuickItem method="GET" path="/v2/projects/{project_id}/analytics/revenue" href="https://docs.botsubscription.com/api/analytics/revenue/" label="Revenue" />
    <ApiQuickItem method="GET" path="/v2/projects/{project_id}/analytics/users" href="https://docs.botsubscription.com/api/analytics/users/" label="New and Total Users" />
    <ApiQuickItem method="GET" path="/v2/projects/{project_id}/analytics/active-users" href="https://docs.botsubscription.com/api/analytics/active-users/" label="Active Users" />
    <ApiQuickItem method="GET" path="/v2/projects/{project_id}/analytics/memberships" href="https://docs.botsubscription.com/api/analytics/memberships/" label="Membership Changes" />
    <ApiQuickItem method="GET" path="/v2/projects/{project_id}/analytics/payments" href="https://docs.botsubscription.com/api/analytics/payments/" label="Payment Statuses" />
    <ApiQuickItem method="GET" path="/v2/projects/{project_id}/analytics/plans" href="https://docs.botsubscription.com/api/analytics/plans/" label="Plan Performance" />
    <ApiQuickItem method="GET" path="/v2/projects/{project_id}/analytics/coupons" href="https://docs.botsubscription.com/api/analytics/coupons/" label="Coupon Performance" />
    <ApiQuickItem method="GET" path="/v2/projects/{project_id}/analytics/retention" href="https://docs.botsubscription.com/api/analytics/retention/" label="Retention Cohorts" />
    <ApiQuickItem method="GET" path="/v2/projects/{project_id}/analytics/funnel" href="https://docs.botsubscription.com/api/analytics/funnel/" label="Purchase Funnel" />
    <ApiQuickItem method="GET" path="/v2/projects/{project_id}/analytics/providers" href="https://docs.botsubscription.com/api/analytics/providers/" label="Payment Providers" />
    <ApiQuickItem method="GET" path="/v2/projects/{project_id}/analytics/revenue-bands" href="https://docs.botsubscription.com/api/analytics/revenue-bands/" label="Revenue Bands" />
    <ApiQuickItem method="GET" path="/v2/projects/{project_id}/analytics/customers" href="https://docs.botsubscription.com/api/analytics/customers/" label="Paying Customers" />
    <ApiQuickItem method="GET" path="/v2/projects/{project_id}/analytics/mrr" href="https://docs.botsubscription.com/api/analytics/mrr/" label="Monthly Recurring Revenue" />
    <ApiQuickItem method="GET" path="/v2/projects/{project_id}/analytics/leaderboard" href="https://docs.botsubscription.com/api/analytics/leaderboard/" label="Customer Rankings" />
    <ApiQuickItem method="GET" path="/v2/projects/{project_id}/analytics/recent" href="https://docs.botsubscription.com/api/analytics/recent/" label="Recent Sales" />
    <ApiQuickItem method="GET" path="/v2/projects/{project_id}/analytics/health" href="https://docs.botsubscription.com/api/analytics/health/" label="Payment Health" />
    <ApiQuickItem method="GET" path="/v2/projects/{project_id}/analytics/trials" href="https://docs.botsubscription.com/api/analytics/trials/" label="Trial Activity" />
    <ApiQuickItem method="GET" path="/v2/projects/{project_id}/analytics/access-codes" href="https://docs.botsubscription.com/api/analytics/access-codes/" label="Access Code Activity" />
  </ApiQuickGroup>
  <ApiQuickGroup title="Subscriptions">
    <ApiQuickItem method="GET" path="/v2/projects/{project_id}/subscriptions/{subscription_id}" href="https://docs.botsubscription.com/api/subscriptions/get/" label="Get Subscription" />
    <ApiQuickItem method="GET" path="/v2/projects/{project_id}/subscriptions" href="https://docs.botsubscription.com/api/subscriptions/list/" label="List Subscriptions" />
    <ApiQuickItem method="GET" path="/v2/projects/{project_id}/subscriptions/{subscription_id}/cancel-options" href="https://docs.botsubscription.com/api/subscriptions/cancel-options/" label="Cancellation Options" />
    <ApiQuickItem method="POST" path="/v2/projects/{project_id}/subscriptions/{subscription_id}/cancel" href="https://docs.botsubscription.com/api/subscriptions/cancel/" label="Cancel Subscription" />
  </ApiQuickGroup>
  <ApiQuickGroup title="Return Offers">
    <ApiQuickItem method="GET" path="/v2/projects/{project_id}/cancel-offer" href="https://docs.botsubscription.com/api/cancel-offers/get/" label="Get Return Offer" />
    <ApiQuickItem method="PUT" path="/v2/projects/{project_id}/cancel-offer" href="https://docs.botsubscription.com/api/cancel-offers/update/" label="Set Return Offer" />
  </ApiQuickGroup>
  <ApiQuickGroup title="Payment History">
    <ApiQuickItem method="GET" path="/v2/projects/{project_id}/payment-history" href="https://docs.botsubscription.com/api/payment-history/list/" label="Payment History" />
  </ApiQuickGroup>
</ApiQuickRef>

## Authentication

Include your project API key in the `Authorization` header:

```
Authorization: Bearer YOUR_API_KEY
```

This REST API reference is for project API keys. Each key can access only its own project. Restricted keys need the scope listed on the endpoint page. Unrestricted keys can use supported endpoints without individual scope grants; endpoint-specific restrictions still apply.

## Language Selection

Specify the language for translated messages by sending an `Accept-Language` header:

```
Accept-Language: bg
```

If the header is omitted, English (`en`) is used.

## Common Response Format

Successful responses with a body use this envelope. A `204 No Content` response has no body; `message` and pagination fields are included only when applicable.

Endpoint examples use fictional IDs, names, dates, amounts and URLs in the response's wire format. Optional fields may be omitted; nullable fields may be `null`. The endpoint's response examples show conditional variants where applicable. Treat metadata described as opaque as an arbitrary JSON object, not a fixed set of example keys.

```json
{
  "ok": true,
  "request_id": "44444444-4444-4444-8444-444444444444",
  "method": "GET",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/users",
  "code": 200,
  "message": "Users retrieved successfully",
  "total": 0,
  "data": []
}
```

### UTC ISO response dates

Timestamp fields defined in REST response bodies use UTC ISO strings with milliseconds: `YYYY-MM-DDTHH:mm:ss.sssZ`, for example `"2030-01-01T00:00:00.000Z"`. Nullable dates remain `null`, and optional dates remain omitted when unset, according to each field's contract.

Counts and durations remain numeric. Arbitrary settings values, custom metadata, and opaque provider JSON keep their original values and types. Analytics calendar labels use date-only or month-only strings as described in the [analytics date format rules](https://docs.botsubscription.com/api/analytics/#date-windows-and-subscription-reports).

### Decimal amounts

Send plan prices, coupon values and checkout amounts as decimal **strings**, such as `"29.99"`. For these inputs, strings must be nonnegative plain decimals with at most 18 fractional digits. Signs, leading zeroes such as `"01"`, and exponent strings such as `"1e-7"` are rejected. Each endpoint can impose additional bounds.

JSON numbers are also accepted, but their parsed value must be no greater than `9007199254740991`, must be reproducible with 15 significant digits, and must fit the decimal range. For example, numeric `0.30000000000000004` is rejected with `422 VALIDATION_ERROR`; send the intended exact amount as a string. A JSON parser can already have rounded a numeric value before validation, so use strings whenever every digit matters.

[Plan prices](https://docs.botsubscription.com/api/plans/create/) also follow the currency's decimal limit: USD permits 2 places, JPY permits 0, BTC permits 8, and ETH permits 18. Trailing zeroes do not add precision: `"10.000"` is valid for USD, while `"10.006"` is rejected.

Non-null monetary amounts returned by the API are strings. Use decimal arithmetic rather than converting response amounts to floating-point numbers.

Revenue totals, including renewal-calendar totals, follow the currency's precision. Do not assume every currency uses two decimal places.

### Error Responses

Business and authentication failures can use a singular `error`:

```json
{
  "ok": false,
  "request_id": "44444444-4444-4444-8444-444444444444",
  "method": "GET",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/users",
  "code": 401,
  "error": {
    "error_code": "UNAUTHORIZED",
    "message": "Invalid or expired authentication token."
  }
}
```

Request-schema validation can return multiple failures in `errors`, even when only one field fails:

```json
{
  "ok": false,
  "request_id": "44444444-4444-4444-8444-444444444444",
  "method": "GET",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/access-tokens/eligibility",
  "code": 422,
  "errors": [
    {
      "message": "query: count is too big; maximum allowed is 100",
      "error_code": "VALIDATION_ERROR"
    }
  ]
}
```

Handle both `error` and `errors`; use `error_code` and HTTP status for branching rather than matching message text.

The singular `error.message` may be omitted. Entries in `errors` require `error_code` and `message`; an optional string `field` may identify the invalid field. Do not require every validation failure to include a field path.

## Error Codes

| Code | Description |
|------|-------------|
| `400` | Bad Request - Invalid input parameters |
| `401` | Unauthorized - Missing or invalid authentication |
| `403` | Forbidden - Credential or project access is not permitted |
| `404` | Not Found - Resource not found in the project |
| `409` | Conflict - State or idempotency conflict |
| `422` | Validation Error - Invalid data format |
| `429` | Too Many Requests - Wait for the indicated retry delay |
| `500` | Server Error - Internal server error |
| `503` | Service Unavailable - Temporary project or service unavailability |

### Temporary project unavailability

Project requests can return `503 SERVICE_UNAVAILABLE`, including during updates or restores. A `Retry-After` header and `error.retry_after_seconds` can indicate how many seconds to wait. Retry reads after that delay.

For writes, follow the endpoint recovery guidance and preserve the original body and `Idempotency-Key` when retrying. A `503` does not establish that no write occurred. Do not switch keys to bypass recovery.

### Idempotency for authenticated writes

`Idempotency-Key` is an **optional HTTP header** supported across authenticated `POST`, `PUT`, `PATCH`, and `DELETE` endpoints in this reference. It is not a body field, query parameter, or additional scope. The playground exposes it under **Headers** on every supported write endpoint.

Choose one key per logical action. Reuse it with the **same API key and unchanged request** after a network failure. Changing the method, route, resource, query, or body can cause a mismatch. Do not generate a new key for every retry. UUID-shaped keys are case-normalized; other nonempty keys are case-sensitive. Blank values are treated as absent.

#### Default replay

Unless an endpoint lists an exception below, a repeated key and request replays the original status and body with `Idempotent-Replayed: true`. A `204` still has no body. Successful responses are normally retained for 24 hours; caller errors other than `409` and `429` are retained for one hour. Handler `5xx`, `409`, and `429` results can execute again on a later retry.

This is retry suppression within finite windows, not an exactly-once guarantee. Do not assume every original response header will be replayed. A response-formatting `5xx` after a write does not establish that the write failed; reconcile resource state before starting a new action.

#### Endpoint-specific recovery

| Endpoints | Behavior |
|---|---|
| Create Payment Request; Redeem for Member | The shared header binds the key to the request without providing the default response replay or concurrency guarantee. Follow the endpoint's recovery guidance. |
| Prepare Tokens; Create Webhook; Install Merchant Account; Verify Provider Webhook | Save the first successful response. A completed keyed success cannot be replayed and is not re-executed under the completed record. |

Payment creation has its own duplicate-submit handling, with a successful rich-response window normally lasting ten minutes. Redemption recovers by the same code and recipient. Neither is a promise of the shared 24-hour response cache.

#### Creation outcomes after a failed response

Create Plan, Create Coupon, and Clone Coupon can save a resource before the response fails. On those failures, `Resource-Created: true` confirms a durable create; `Resource-Created: false` explicitly confirms refusal before writing. An absent header means the outcome is unknown. `Response-Validation-Failed: true` reports output validation failure and can accompany a confirmed create.

These headers are absent on successful responses. Preserve the original `Idempotency-Key` and request while reconciling. If creation committed but its response could not be returned, retry can produce `409 IDEMPOTENCY_RESPONSE_NOT_REPLAYABLE` with optional `error.details` entries containing `resource_type` and `resource_id`. Use those IDs to read the saved resource. Missing details do not justify repeating the create with a new key.

#### Idempotency errors

| Status and error | Recovery |
|---|---|
| `422 IDEMPOTENCY_KEY_MISMATCH` | The key is bound to a different request. Reconcile the original action; use a new key only for a new intent. |
| `409 IDEMPOTENCY_KEY_IN_PROGRESS` | The first attempt is still running. Wait for `Retry-After` and retry unchanged. |
| `409 IDEMPOTENCY_RESPONSE_NOT_REPLAYABLE` | Read resource state or follow endpoint recovery instructions. This does not prove completion and does not justify a duplicate action with a new key. |
| `503 IDEMPOTENCY_UNAVAILABLE` | Wait for `Retry-After` and retry the same key and request. |
| `429 IDEMPOTENCY_KEY_LIMIT_EXCEEDED` | Wait for the key window to reset, as indicated by `Retry-After`. The request was not executed. |

Nonreplayable results can also follow a response that exceeds replay storage limits or an operation that outlives its admission lease. Preserve the original request while resolving an uncertain result.

Default new-key budgets are 20,000 per caller per 24 hours for replay/nonreplayable routes, with a 100,000 admission threshold for guard-only routes using the same counter. Defaults are configurable. Response replay is also bounded by 512 KiB per response and 8 MiB retained response bytes per caller/window. These limits are separate from request rate limits.

## Pagination

List endpoints support pagination using the following query parameters:

| Parameter | Description |
|-----------|-------------|
| `limit` | Number of items per page (default varies by endpoint) |
| `offset` | Number of items to skip (default: 0) |

## Outbound Webhooks (Real-Time Events)

For server-to-server integrations, BotSubscription supports outbound webhooks. You can register HTTPS POST endpoints per project to receive real-time notifications for payment completion and other platform events.

To get started, see our comprehensive [Webhooks Overview](https://docs.botsubscription.com/webhooks/overview/) or explore active events like [payment-request.completed](https://docs.botsubscription.com/webhooks/events/payments/payment-request-completed/).

## Health Check

- **GET** `/ping`
- No authentication required
- Returns: `{ "ok": true }`
