# Open the customer portal

`POST /api/v1/billing/portal-sessions`

Open Stripe's own customer portal and answer the page to send the owner to.

The portal is where invoices are read and the card on file is changed. Cancelling, resuming and moving up are turned off there on purpose, so that those decisions are made in one place, through this API or the product.

## Returns

A portal_session object carrying the URL. 422 when Stripe does not know the account yet, which is the case until something has been paid, and 503 when Stripe did not answer.

- `data` (object): The portal session that was opened.
- `data.type` (string): Always portal_session.
- `data.attributes` (object): Everything the record holds.
- `data.attributes.url` (string): The page at Stripe where the owner reads their invoices and changes the card on file. It is short lived, so open it rather than storing it.

## Rate limit

Sixty requests per minute, per user, shared by every key and device. Every answer carries the budget left in `X-RateLimit-Remaining`.

## Request

```sh
curl https://my.monicahq.com/api/v1/billing/portal-sessions \
  -X POST \
  -H "Authorization: Bearer $MONICA_TOKEN"
```

```javascript
const response = await fetch('https://my.monicahq.com/api/v1/billing/portal-sessions', {
  method: 'POST',
  headers: { Authorization: `Bearer ${token}` },
})
const data = await response.json()
```

```php
$response = Http::withToken($token)->post('https://my.monicahq.com/api/v1/billing/portal-sessions');
```

## Response

`201`

```json
{
    "data": {
        "type": "portal_session",
        "attributes": {
            "url": "https://billing.stripe.com/p/session/test_a1dundermifflin"
        }
    }
}
```
