Confirm this change

API reference 4 min read

ERP billing API

Manage service credits, checkout, invoices and subscription changes from your platform.

On this page

Issue a scoped billing key

An owner/admin issues a new key through POST /api/platform/api-keys with their dashboard authorization, x-workspace-id and JSON {"name":"ERP billing","scopes":["billing:read","billing:checkout","billing:subscription","usage:read"]}. Existing keys do not gain financial access. Add platform:access only if this key should also use messaging/templates. Store the returned key on your ERP server, never in browser/mobile code. Financial permissions remain bound to the issuer’s current owner/admin membership. Revoking the key or removing that membership disables access.

Billing profile and catalog

GET /api/platform/billing/catalog returns authoritative prices, rates and creditPolicy. GET /api/platform/billing/profile returns billing fields and updatedAt. PUT profile requires billing:checkout, Idempotency-Key and expectedUpdatedAt. Only documented billing identity/address/tax-ID fields are editable; export tax approval remains a platform finance decision. No organization or workspace ownership fields can be changed here.

Quote, pay and reconcile

POST /api/platform/billing/quotes with packageId, currency (INR/USD), term (monthly/annual), optional couponCode, extraSeats and extraNumbers. It returns a tax-inclusive, expiring quote. POST /api/platform/billing/checkout with quoteId creates or resumes the authoritative provider order. Open Razorpay Checkout in your ERP using returned keyId, orderId, amount and currency. Payment credentials are collected by Razorpay. POST /api/platform/billing/payments/verify with orderId, paymentId and signature returned by Checkout. Only server-verified captured payment can grant credits. Subscription purchases additionally require billing:subscription. Customer payment collection links are a separate product and cannot activate service credits.

Idempotency and recovery

All platform billing POST/PUT requests require an Idempotency-Key (8–128 letters, digits, dots, colons, underscores or hyphens). Reuse the exact key and payload on retries. Concurrent calls share one durable request; changed payload/path/method returns 409. A pending result is HTTP 202 BILLING_REQUEST_PENDING: inspect GET /api/platform/billing/requests?id=... or ?key=..., GET payments?id=<quoteId>, and GET checkout?quoteId=... . Do not create another purchase on an unknown outcome. Stored responses are replayed and may be stale; fetch current payment/plan state separately. Correct an explicit rejected request with a new key.

Credits and detailed usage

GET /api/platform/billing/credits (billing:read) returns balance, totals by bucket kind, paginated credit transactions and bucketHistory including validity. offset pages transactions (20 per page); bucketOffset pages buckets (20). Filters: type, operationId, paymentReference, bucketId, from and to. GET /api/platform/usage (usage:read) returns up to 50 operations with senderId, templateName, category, apiKey label, attempts, safe lastError code and providerMessageId. Filters: state, senderId, templateName, apiKeyId, channel, providerMessageId, id, from, to and offset. Date filters use ISO-8601 timestamps, inclusive from and exclusive to. Offset is 0–100000.

Payment history and documents

GET /api/platform/billing/payments supports id (the quote/payment record ID), orderId, status, type, from, to and offset; returns up to 50 with nextOffset. GET /api/platform/billing/invoices returns invoices, payment history and credit notes in pages of 10; ?format=csv exports that invoice page. GET /api/platform/billing/invoices/download?number=<number>&kind=invoice or credit-note downloads a private PDF. These require billing:read and are always scoped to the key’s workspace. GET checkout?quoteId=<id> requires billing:checkout and exposes resumable provider Checkout details without creating another order.

Plan changes and renewal

GET /api/platform/billing/plan (billing:read) returns current plan, version, limits and scheduled change. For an upgrade/renewal, use a new server quote and verified checkout. For a future change, POST quotes with scheduled:true, then PUT plan with {"action":"change","quoteId":"...","version":<current version>}. PUT plan also accepts action cancel or withdraw with the current version. Mutations require billing:subscription; purchases require both checkout and subscription permissions. Concurrent stale versions fail with 409. Cancellation ends access at the paid term boundary; this does not withdraw purchased service credits.

Billing webhooks and accounting

Subscribe to billing.* or selected events using existing webhook setup. Existing events include billing.low_credit, billing.payment_received, billing.renewal_notice, billing.usage_settled, billing.usage_released and billing.quota_warning. Added events: billing.credits_granted, billing.credits_expired, billing.credits_returned, billing.subscription_changed, billing.invoice_issued, billing.credit_note_issued, billing.profile_updated, billing.access_changed and billing.payment_adjustment. Events use the durable outbox, stable event IDs, timestamped HMAC signatures and existing replay/retry semantics. Verify raw bytes and deduplicate event IDs. Delivery is at least once and order is not guaranteed; fetch current state for reconciliation. Service credits settle on provider acceptance, not message delivery. Explicit send rejection releases still-valid allocations; unknown outcomes remain reserved. Transport retry does not charge again. Reviewed credit returns and money refunds are different operations and are not self-service API grants.

Operational limits

Platform billing reads and mutations share a workspace rate bucket: reads enforce 120 requests per minute, mutations 30. Payloads are limited to 32 KiB. Existing ingress, usage and provider limits also apply. Billing recovery is available while sending is frozen or onboarding is incomplete; security-suspended and closed workspaces remain blocked. Recurring authorization still requires the existing owner consent flow; issuing a billing key does not enroll anyone in automatic charging.

Read balances from your backend

Example
curl "$CONNECT_ORIGIN/api/platform/billing/credits?offset=0&bucketOffset=0" \
  -H "x-api-key: $CONNECT_BILLING_KEY"

Display balance and history

The credits response contains balance, buckets, transactions, nextOffset, bucketHistory and nextBucketOffset. Follow the two offsets independently until null. Display current balance separately from historical balanceAfter; do not add historical entries to calculate spendable credits. Keep amounts/currency and timestamps as returned, and honor bucket expiry. For usage, read /api/platform/usage with its own pagination. Fetch current state after verified payment rather than trusting a cached checkout response.

Need help with this guide? Contact support