# Customer portal

> Sign a customer in to your customer portal from your own site, so they see their orders, receipts and invoices with you without asking for a code.

Source: https://railbed.com/docs/api/customer-portal/ · Updated: 2026-11-23 · Railbed developer docs

For AI assistants: the index of every docs page, with the rules for an integration, is https://railbed.com/docs/llms.txt

## How it works

Your customer portal is one page where each of your customers sees what they bought from you: their orders with a receipt for each one paid, their invoices with **Pay**, and their own contact details. A customer signs in there with a code emailed to the address they bought with. Turn it on in the dashboard under [Customers → Customer portal](https://app.railbed.io/customers).

When the customer is already signed in to your own site, skip the code: your server asks for a customer portal session and sends the customer to its `url`.

1. Your server calls [Create a customer portal session](#create-a-customer-portal-session) with the customer's id or email.
2. Redirect the customer's browser to `url` straight away.
3. The portal opens signed in, for an hour. Its **Back** link goes to your `return_url`.

The `url` opens once and only for 5 minutes. Make a new one each time the customer asks for their portal, never ahead of time, and never put one in an email or a page another person could see: whoever opens it first is signed in as that customer.

> [!NOTE]
> The portal never takes or refunds money itself. A customer pays an invoice or an unpaid order on its ordinary page, and a refund is between you and the customer, as the portal's help card tells them.

## Retrieve the customer portal

`GET /v1/customer_portal`

Returns your portal's settings as they stand in the key's mode: whether it's on, its address, its words, which sections customers see and the links it shows. Check `enabled` before offering customers a link to it. The settings are changed in the dashboard, under **Customers → Customer portal**.

Example: cURL

```bash
curl https://pay.railbed.io/v1/customer_portal \
  -H "Authorization: Bearer $RAILBED_SECRET_KEY"
```

Example: Response · response 200 OK

```json
{
  "object": "customer_portal",
  "enabled": true,
  "url": "https://pay.railbed.io/portal/northwind-studio-k7rq",
  "headline": null,
  "welcome": "Your orders, receipts and invoices from Northwind Studio.",
  "help_text": "Refunds within 30 days of purchase.",
  "receipt_details": null,
  "sections": {
    "invoices": true,
    "receipts": true,
    "edit_details": true,
    "marketing": false,
    "preferred_provider": true,
    "subscriptions": true
  },
  "links": {
    "support_email": "help@northwind.example",
    "support_url": null,
    "refund_policy_url": "https://northwind.example/refunds",
    "terms_url": null,
    "privacy_url": null,
    "website_url": "https://northwind.example"
  }
}
```

| Field | Type | Description |
|---|---|---|
| `enabled` | boolean | `true` while the portal is on. Portal sessions need it on |
| `url` | string or null | Where customers sign in with a code sent to their email. `null` while the portal is off |
| `headline`, `welcome`, `help_text`, `receipt_details` | string or null | The words you set, or `null` for the portal's own |
| `sections` | object | `invoices`, `receipts`, `edit_details`, `marketing`, `preferred_provider` and `subscriptions`, each `true` when customers see it |
| `links` | object | `support_email`, `support_url`, `refund_policy_url`, `terms_url`, `privacy_url` and `website_url`, or `null` |

It needs the `customers:read` [scope](https://railbed.com/docs/api.md#scopes), which **Read only** keys have.

## The customer portal session object

| Field | Type | Description |
|---|---|---|
| `object` | string | `"customer_portal_session"` |
| `customer` | string | The [customer](https://railbed.com/docs/api/customers.md) it signs in, `cus_…` |
| `livemode` | boolean | `false` for Test mode, `true` for Live mode: the key's mode |
| `url` | string | Send the customer here. It opens once, then signs them in for an hour |
| `return_url` | string or null | Where the portal's **Back** link goes, as you sent it |
| `expires_at` | integer | When `url` stops opening, in Unix seconds: 5 minutes after it was made |

Example: A customer portal session · response 201 Created

```json
{
  "object": "customer_portal_session",
  "customer": "cus_Hc7nQ2wVz9KpT4mRb1Ye",
  "livemode": true,
  "url": "https://pay.railbed.io/portal/northwind-studio-k7rq#t=Qm9KcW1xV3pYcjRkTjhwTGs2SnRZdjNiSGY1Uw2RzAx",
  "return_url": "https://northwind.example/account",
  "expires_at": 1790380825
}
```

## Create a customer portal session

`POST /v1/customer_portal/sessions`

Makes a single-use link to your customer portal for one customer, in the key's mode. Name the customer with `customer` or `email`, not both.

| Parameter | Type | Description |
|---|---|---|
| `customer` | string | The customer's id, `cus_…` |
| `email` | string | Their email, in any letter case, when you don't keep their id |
| `return_url` | string | Optional. Where the portal's **Back** link goes, such as your account page. A full `https://` address in Live mode; Test mode also allows `http://localhost`. Left out, the portal shows the website from its settings, if any |

Example: cURL

```bash
curl https://pay.railbed.io/v1/customer_portal/sessions \
  -H "Authorization: Bearer $RAILBED_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{"customer": "cus_Hc7nQ2wVz9KpT4mRb1Ye", "return_url": "https://northwind.example/account"}'
```

Example: Node\.js

```js
// In your "Orders and receipts" route, for the signed-in customer.
const session = await fetch('https://pay.railbed.io/v1/customer_portal/sessions', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.RAILBED_SECRET_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ customer: user.railbedCustomerId, return_url: 'https://northwind.example/account' }),
}).then((r) => r.json());
res.redirect(303, session.url);
```

Example: Python

```python
session = requests.post(
    "https://pay.railbed.io/v1/customer_portal/sessions",
    headers={"Authorization": f"Bearer {os.environ['RAILBED_SECRET_KEY']}"},
    json={"email": user.email, "return_url": "https://northwind.example/account"},
    timeout=15,
).json()
return redirect(session["url"], code=303)
```

Example: PHP

```php
<?php
$ch = curl_init('https://pay.railbed.io/v1/customer_portal/sessions');
curl_setopt_array($ch, [
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_POST => true,
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer ' . getenv('RAILBED_SECRET_KEY'),
    'Content-Type: application/json',
  ],
  CURLOPT_POSTFIELDS => json_encode(['email' => $user['email'], 'return_url' => 'https://northwind.example/account']),
]);
$session = json_decode(curl_exec($ch), true);
header('Location: ' . $session['url'], true, 303);
```

Example: Response · response 201 Created

```json
{
  "object": "customer_portal_session",
  "customer": "cus_Hc7nQ2wVz9KpT4mRb1Ye",
  "livemode": true,
  "url": "https://pay.railbed.io/portal/northwind-studio-k7rq#t=Qm9KcW1xV3pYcjRkTjhwTGs2SnRZdjNiSGY1Uw2RzAx",
  "return_url": "https://northwind.example/account",
  "expires_at": 1790380825
}
```

It needs the `orders:write` [scope](https://railbed.com/docs/api.md#scopes), so a Read only key can't sign customers in. Each call makes a new link: a call that failed is safe to send again, and a link nobody opened expires by itself.

| Response | Cause |
|---|---|
| `404 not_found` | No customer of yours has that id or email in this key's mode, or you [deleted their details](https://railbed.com/docs/api/customers.md#deleted-customers) |
| `409 portal_off` | The customer portal is off. Turn it on in the dashboard first |
| `400 invalid_customer` | Neither `customer` nor `email` was sent, or both were, or `customer` isn't a customer id |
| `400 invalid_url` | `return_url` isn't an address the portal may use, by the rules of a session's `success_url` |

A link opened after it was used or expired shows the portal's sign-in card, where the customer gets a code by email instead.
