API reference

Billing portal

Create a customer portal session

POST/v1/billing_portal/sessions

Creates a short-lived link to the hosted customer portal, where your customer sees their subscriptions and next charge, cancels at period end (and undoes it), updates their card and pays an open invoice. Use it behind a Manage billing button in your signed-in app, one session per click.

Arguments: customer (cus_...), return_url (optional: https, http for localhost in test mode; in live mode the host must be on your live redirect list). Needs subscriptions:write, payment_methods:write and payment_methods:charge (the portal saves and charges cards).

Returns a billing_portal.session: id (bps_...), object, created, customer, livemode, return_url, url, expires_at. Redirect your signed-in user to url at once: it works once and expires 5 minutes after creation. Never email it, store it or show it. Each call makes a new session. Monetize.Pay sends no email to customers: send your own from the billing events.

Errors: parameter_invalid, url_invalid (400); resource_missing (404, also for a deleted customer).

Next step: redirect the browser to url.

Parameters

NameDescription
MonetizePay-Accountheader, string or null

Optional. The merchant (mch_...) this request acts on, when the body has no merchant_id: the analogue of Stripe's Stripe-Account header.

Stripe-Accountheader, string or null

Optional. A synonym of MonetizePay-Account; holds a merchant id (mch_...).

Request body

FieldDescription
customerstringRequired

The customer (cus_...) the portal is for.

return_urlstring or null

Where the portal's back link goes: https (http for localhost in test mode); in live mode the host must be on your live redirect list.

Responses

StatusDescriptionBody
200

Successful Response

object
400

Invalid request. A parameter, header or body field failed validation (code parameter_invalid, with param naming it), or another invalid_request code this operation's description lists. Fix the request; do not retry it unchanged.

ErrorResponse
401

The API key is missing, malformed, unknown or revoked (api_key_missing, api_key_malformed, api_key_invalid). Fix the Authorization header.

ErrorResponse
403

The key is valid but may not do this: platform_suspended, insufficient_scope, live_mode_unavailable, or a permission code this operation's description lists (for example processor_currency_unsupported).

ErrorResponse
404

No such resource for this platform (resource_missing), or another not_found code this operation's description lists.

ErrorResponse
413

The request body is over 1048576 bytes, or its Content-Length is not a number (code payload_too_large). Every write method is checked, before routing. A body sent without a Content-Length (chunked) is accepted on /v1 and counted as it arrives; elsewhere it is refused. The connection is closed after this answer. Send a smaller body.

ErrorResponse
429

Too many requests (rate_limited). Wait for the Retry-After header, then retry.

ErrorResponse

Example

curl
curl -X POST "https://api.monetize.pay/v1/billing_portal/sessions" \
  -H "Authorization: Bearer zp_test_..." \
  -H "Content-Type: application/json" \
  -d '{
    "customer": <customer>
  }'
Python
import requests

response = requests.post(
    "https://api.monetize.pay/v1/billing_portal/sessions",
    headers={
        "Authorization": "Bearer zp_test_...",
    },
    json={
        "customer": "<customer>",
    },
)
print(response.json())
Node.js
const response = await fetch("https://api.monetize.pay/v1/billing_portal/sessions", {
  method: "POST",
  headers: {
    "Authorization": "Bearer zp_test_...",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "customer": "<customer>",
  }),
});
console.log(await response.json());