> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stateset.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a portal handler

> Creates a Stripe Billing Portal session for self-service subscription management (upgrade, cancel, payment methods, invoices). **Required scope:** billing:write

Creates a Stripe Billing Portal session for self-service subscription
management (upgrade, cancel, payment methods, invoices).

**Required scope:** `billing:write`

### Request body

`CreatePortalRequest`

<ParamField body="return_url" type="string" required>
  URL to return to after the customer finishes in the portal
</ParamField>

### Response

`CreatePortalResponse`

<ResponseField name="portal_url" type="string" required>
  Full Stripe Billing Portal URL
</ResponseField>

### Status codes

| Code  | Meaning                                            |
| ----- | -------------------------------------------------- |
| `200` | Portal session created                             |
| `401` | Unauthorized — missing or invalid credentials      |
| `403` | Forbidden — the key/token lacks the required scope |
| `429` | Rate limited — see Retry-After / X-RateLimit-Reset |
| `503` | Billing not configured                             |

<RequestExample>
  ```bash cURL theme={null}
  curl --request POST \
    --url 'https://api.nsr.stateset.com/api/v1/billing/portal' \
    --header 'X-API-Key: YOUR_API_KEY' \
    --header 'Content-Type: application/json' \
    --data '{
    "return_url": "https://example.com/webhooks/stateset"
  }'
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  {
    "portal_url": "string"
  }
  ```
</ResponseExample>
