Skip to content
KomashiKomashi

REST API integration

Use the REST API to connect your backend to Komashi. The API supports catalog discovery, customer and contact management, subscriptions, checkout links, usage and invoice lookups.

The full list of REST API routes is available in the interactive OpenAPI reference: komashi.com/api-docs.

Open Control Center → Integration → API. The page displays Documentation and API endpoint. Copy the endpoint shown there; it already includes the version prefix.

API Keys page showing the documentation link and API endpoint

For the public service, the versioned endpoint is:

https://api.komashi.com/v1

A local development environment can use a different host and path, such as https://komashi-app.test/api/v1. Use the value displayed in your environment instead of adding /api or /v1 by guesswork.

The Documentation link opens the interactive OpenAPI reference. Use it for each operation’s exact request fields, response schema and validation rules.

Create a provider key under Integration → API. Send it in the Authorization header, and request JSON responses:

Terminal window
export KOMASHI_API_BASE='https://api.komashi.com/v1'
export KOMASHI_API_KEY='YOUR_PROVIDER_API_KEY'
curl "$KOMASHI_API_BASE/services" \
-H "Authorization: Bearer $KOMASHI_API_KEY" \
-H 'Accept: application/json'

Use a backend environment variable or secret store for the real key. It identifies the provider, so ordinary provider-key requests do not need a separate provider ID header.

The key must have the ability required by the operation. Read access is sufficient for this first request. Checkout creation requires Create; usage updates and subscription cancellation require Update. Do not infer the permission solely from the HTTP method.

Responses include these common fields:

{
"succeeded": true,
"status_code": 200,
"data": []
}

data contains the result. Depending on the operation, it can be a resource, an array, a checkout result or null. Additional fields such as message, validation errors, links and meta can appear alongside the common fields. Endpoint errors carry a stable code field, for example SERVICE_NOT_FOUND or CATALOG_CHANGE_INVALID. Branch on code rather than on the message text, which can be localized or reworded. Generic errors, such as an authentication failure or a rate limit, may not include code; check the HTTP status as well.

A successful operation that internally produces 204 No Content is returned as HTTP 200 with data: null. Check the HTTP status and the response fields rather than expecting a 204 for every deletion.

Paginated list operations accept page and per_page. The default page size is 25, and the maximum is 100. Preserve pagination information such as links and meta when it is present.

Terminal window
curl "$KOMASHI_API_BASE/customers?page=1&per_page=25" \
-H "Authorization: Bearer $KOMASHI_API_KEY" \
-H 'Accept: application/json'

Paths below are relative to the versioned API endpoint.

RequestPurpose
GET /servicesList services.
GET /services/{service}Get one service.
GET /services/{service}/plansList its plans.
GET /services/{service}/plans/{plan_id}/periodsList a plan’s periods.
GET /services/{service}/addonsList add-ons.
GET /services/{service}/addons/{addon_id}/optionsList add-on options.
GET /services/{service}/service-prices/discountsRead available discounts.
GET /services/{service}/catalogRead the service’s whole catalog in one response.

Fetch the service, then its plans, periods, add-ons and options. Use identifiers from these results.

Plans, periods and add-ons can be changed in two steps:

RequestPurposeKey ability
GET /services/{service}/catalogRead the current catalog.Read
POST /services/{service}/catalog/previewValidate a change and return its diff, warnings and a change_token. Writes nothing.Update
POST /services/{service}/catalog/applyApply a previewed change with its change_token. This changes the live catalog.Update

The change token is valid for 30 minutes. Apply returns 409 if the catalog changed since the preview (run the preview again) and 410 if the token has expired. The service currency cannot be changed. An applied change sends the same plan, period and add-on webhook events as a change made in the Control Center; the preview sends none. Coupon discounts are still configured in the Control Center.

The API supports customer list, detail, create, update and delete operations under /customers, and contact operations under /customers/{customer_id}/contacts. Deleting a customer is refused with CUSTOMER_HAS_PAYMENT_IN_PROGRESS while one of their payments is still in progress; try again once it has finished.

Creating a customer requires billing details, including billing_name, billing_address, billing_zip, billing_city and billing_country. Depending on the country, a billing state is also required. Provider-defined required customer fields still apply. See the OpenAPI reference before assembling the request.

To create a subscription checkout, send POST /services/{service}/subscriptions. The following is an illustrative request body; replace every identifier with a real value from your provider:

{
"customer_id": "CUSTOMER_UUID",
"plan_id": "PLAN_UUID",
"period_id": "PERIOD_UUID",
"quantity": 1,
"external_reference": "your-internal-order-reference",
"return_url": "https://your-app.example/subscription/return",
"cancel_url": "https://your-app.example/subscription/cancel"
}

Send JSON with Content-Type: application/json. The response’s data includes checkout_url, subscription_id, group_id and the created subscription items. Direct the customer to checkout_url to continue the checkout. The return URL tells you where the browser returned; confirm the current subscription state before granting paid access.

The created subscription is a draft (is_draft: true) until it is paid. To discard an unpaid draft right away, send DELETE /subscriptions/{subscription_id}/draft; this deletes it immediately and sends a subscription.delete webhook. Otherwise an unpaid draft is deleted automatically 24 hours after creation. No webhook is sent for this automatic deletion, so do not rely on one; create a new checkout if the customer returns later.

RequestPurpose
GET /services/{service}/subscriptionsList subscriptions for a service.
GET /subscriptions/{subscription_id}Read one subscription.
GET /subscriptions/groups/{group_id}Read a subscription group.
POST /subscriptions/{subscription_id}/payment-linkGenerate an available payment link for an existing subscription.
POST /subscriptions/{subscription_id}/change-planRequest a plan change using the target configuration.
PATCH /subscriptions/{subscription_id}/datesUpdate supported lifecycle dates.
PATCH /subscriptions/{subscription_id}/statusUpdate the status and optional renewal setting.
DELETE /subscriptions/{subscription_id}/cancelCancel a subscription or a pending plan change.
DELETE /subscriptions/{subscription_id}/draftDelete an unpaid draft immediately; sends subscription.delete.
GET /invoices and GET /invoices/{invoice_id}Read invoice records.

Cancellation follows the provider’s cancellation settings. A group ID cannot replace the individual subscription ID required by these operations. Plan-change and payment-link operations have their own business-state requirements; inspect the reference and returned errors.

Read GET /subscriptions/{subscription_id}/usage before relying on an allowance. Group usage is available through GET /subscriptions/groups/{group_id}/usage.

For POST /subscriptions/{subscription_id}/sync-usage, send the new absolute total:

{ "usage": 125 }

For POST /subscriptions/{subscription_id}/adjust-usage, send an increment or decrement:

{ "action": "increase", "value": 1 }

Supported actions are increase and decrease; omitting value uses 1. Repeating an adjustment applies it again, so do not blindly retry a write after a network timeout. Read the current state first when the result is uncertain.

StatusWhat to check
401Missing, invalid or deleted key.
403Wrong token type or insufficient ability.
404Unknown record or a record outside the current provider.
409A business-state conflict, such as a draft, an incompatible pending operation, or a catalog that changed since its preview.
410The catalog change_token has expired or does not exist; run the preview again.
422Invalid fields, unsupported values or a business validation failure.
429Request limit reached; wait and retry with backoff.
5xxServer-side failure; preserve enough context to investigate before repeating a write.

The configured REST limit is 100 requests per minute. Handle 429 responses even if you believe your own integration is below the limit.

Related: API keys, webhooks, MCP integration.