Customers
A customer is one buyer's email address in one mode, with the contact details and addresses their orders brought. Read customers to see who bought what, find one by email, and correct their contact details.
On this page
The customer object
| Field | Type | Description |
|---|---|---|
id | string | The customer's id, cus_… |
object | string | "customer" |
livemode | boolean | false for Test mode, true for Live mode |
email | string or null | Their email, lowercased. Null after you delete their details |
name | string or null | Their name, from their latest order that had one |
phone | string or null | Their phone number, as your store sent it |
date_of_birth | string or null | YYYY-MM-DD, from a checkout that asked for it, your session's customer.date_of_birth, or the merchant's edit. Self-declared |
accepts_marketing | boolean | true once they joined the merchant's email list: the box at a checkout that offers it, customer.accepts_marketing on a session, or the merchant's edit |
accepts_marketing_updated_at | integer or null | When accepts_marketing last changed, in Unix seconds |
shipping_address | object or null | Their latest shipping address, in the order's address shape |
billing_address | object or null | Their latest billing address |
store_accounts | array | Their ids in your stores, one per store: platform, store_id, store_name and customer_id (the customer.id you sent). Empty when you sent none |
orders_count | integer | How many orders they have, paid or not |
paid_orders_count | integer | How many of those are paid |
spent | object | What their paid payments add up to, by currency, such as { "USD": "135.31" }. Empty until a payment is paid |
created | integer | When they first appeared, in Unix seconds |
last_order_at | integer or null | When their latest order was created, in Unix seconds |
erased | boolean | true once you've deleted their details |
version | integer | Moves on with every edit to their contact details: your team's, the API's, or the customer's own in the portal. A detail they give at a checkout doesn't move it. Send it back as expected_version on Update a customer |
spent adds up the amount of each of their payments that's paid, in its currency: what they paid, including a part-payment on an order that's held, and both payments when they paid one order twice. paid_orders_count counts only orders that are paid. What reached your wallet is on each payment.
{
"id": "cus_Hc7nQ2wVz9KpT4mRb1Ye",
"object": "customer",
"livemode": true,
"email": "maya@example.com",
"name": "Maya Okafor",
"phone": "+1 503 555 0142",
"date_of_birth": null,
"accepts_marketing": false,
"accepts_marketing_updated_at": null,
"shipping_address": {
"name": "Maya Okafor",
"line1": "418 Linden Avenue",
"line2": "Apt 3B",
"city": "Portland",
"region": "OR",
"postal_code": "97214",
"country": "US"
},
"billing_address": null,
"store_accounts": [],
"orders_count": 3,
"paid_orders_count": 2,
"spent": { "USD": "224.31" },
"created": 1787702525,
"last_order_at": 1790380525,
"erased": false,
"version": 2
}How customers are made
- One customer per email address, in each mode. Case doesn't matter:
Maya@Example.comandmaya@example.comare one customer. Test and Live customers are separate. - The email comes from the session. A session's
customer_email(orcustomer.email) makes or finds the customer when it's created; a session created without one gets its customer from the email given when it starts. Railbed's checkouts and payment links use the email the buyer enters, or the one you set on the link. - The latest details win. Each order's
customer.name,customer.phone,customer.date_of_birthand addresses replace the saved ones. Details an order leaves out keep their earlier value.accepts_marketingonly ever joins:truesets it,falseleaves it. - Buyers add their own. A checkout or session that asks for details (
collect) writes what the buyer gives to the order and the customer when the payment starts. - Details wait for the email. A session created without an email keeps its name, phone and addresses on the order, and saves them to the customer once the buyer gives their email and starts paying.
- Orders follow the email. When a session starts with a different email from the one it was created with, its order moves to the customer with the new email.
The API doesn't create or delete customers: they're made through orders. Their contact details change through orders, through Update a customer, through your team's edits in the dashboard, and through the customer's own Your details in your customer portal. The dashboard also keeps a private note on each customer; the note is never returned by the API or sent in webhooks.
Deleted customers
When a buyer asks you to delete their data, open the customer in the dashboard's Customers and choose Delete customer data. It removes their name, email, phone, date of birth, email-list mark, addresses and answers from the customer, from their orders and payments, and from the bodies stored in your webhook delivery log, and the device, browser, language, time zone, country and IP address their payments were started from. Their orders, amounts and payments stay for your records. It can't be undone.
- The customer keeps its
id, witherased: trueand its contact details and addressesnull. Their orders keepcustomer_id, and their payments'customer_emailbecomesnull. - Their email is no longer on file, so listing by email doesn't find them, and the same email later starts a new customer.
- Webhooks already delivered can't be recalled. Delete the details from your own systems too.
Retrieve a customer
GET /v1/customers/:id
Returns a customer of yours in the key's mode. Another account's customer, or one in the other mode, is 404 not_found.
curl https://pay.railbed.io/v1/customers/cus_Hc7nQ2wVz9KpT4mRb1Ye \
-H "Authorization: Bearer $RAILBED_SECRET_KEY"const customer = await fetch(`https://pay.railbed.io/v1/customers/${id}`, {
headers: { Authorization: `Bearer ${process.env.RAILBED_SECRET_KEY}` },
}).then((r) => r.json());customer = requests.get(
f"https://pay.railbed.io/v1/customers/{id}",
headers={"Authorization": f"Bearer {os.environ['RAILBED_SECRET_KEY']}"},
timeout=15,
).json()<?php
$ch = curl_init('https://pay.railbed.io/v1/customers/' . rawurlencode($id));
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('RAILBED_SECRET_KEY'),
],
]);
$customer = json_decode(curl_exec($ch), true);The response is the customer object. An order's customer_id leads here; for their orders, list orders with customer_id.
Update a customer
PATCH /v1/customers/:id
Changes a customer's contact details by the dashboard's rules: only the fields you send change, and null clears one. The change is on the customer's activity in the dashboard as your key's or agent's, naming the fields but never their values. Nothing is sent to the customer, so change accepts_marketing only with their consent.
| Parameter | Type | Description |
|---|---|---|
name | string or null | Up to 120 characters |
email | string | Their new email, kept lowercased. It can't be removed: a customer is known by it |
phone | string or null | Digits, spaces and + ( ) . -, up to 40 characters |
date_of_birth | string or null | YYYY-MM-DD |
shipping_address, billing_address | object or null | name, line1, line2, city, region, postal_code and country (two letters). Without name, the address is named after the customer |
accepts_marketing | boolean | Whether they're on your email list |
expected_version | integer | The version you read. If their details changed since, it answers 409 edit_conflict instead of overwriting the change. Without it, your change applies to the customer as it is when the request arrives |
curl -X PATCH https://pay.railbed.io/v1/customers/cus_Rk8mW3pZ6tQv1NxLc4Ys \
-H "Authorization: Bearer $RAILBED_SECRET_KEY" \
-H "Content-Type: application/json" \
-d '{ "phone": "+44 20 7946 0000", "expected_version": 1 }'{
"id": "cus_Rk8mW3pZ6tQv1NxLc4Ys",
"object": "customer",
"livemode": false,
"email": "ada@example.com",
"name": "Ada Lovelace",
"phone": "+44 20 7946 0000",
"date_of_birth": null,
"accepts_marketing": true,
"accepts_marketing_updated_at": 1790380525,
"shipping_address": {
"name": "Ada Lovelace",
"line1": "12 St James’s Square",
"line2": null,
"city": "London",
"region": null,
"postal_code": "SW1Y 4LB",
"country": "GB"
},
"billing_address": null,
"store_accounts": [],
"orders_count": 3,
"paid_orders_count": 2,
"spent": {
"USD": "98.00"
},
"created": 1789170925,
"last_order_at": 1790380525,
"erased": false,
"version": 2
}The team's private note on a customer is the dashboard's alone.
| Error | Cause |
|---|---|
409 edit_conflict | Their details changed since expected_version, or while your request ran. Read the customer again, then send your change |
409 email_in_use | Another of your customers in this mode already has that email |
409 erased | You deleted their details, so they can't be edited |
400 unknown_field | A field this request doesn't take, such as note |
It needs the orders:write scope, which Full access keys and agents with full access have.
List customers
GET /v1/customers
Returns your customers in the key's mode, newest first by created. Pass email to find one buyer.
| Parameter | Type | Description |
|---|---|---|
limit | integer | 1–100. Default 20 |
starting_after | string | A customer id from the previous page's next_cursor |
email | string | Only the customer with this email, in any letter case. Matches the whole address |
curl -G https://pay.railbed.io/v1/customers \
--data-urlencode "email=maya@example.com" \
-H "Authorization: Bearer $RAILBED_SECRET_KEY"const url = new URL('https://pay.railbed.io/v1/customers');
url.searchParams.set('email', 'maya@example.com');
const page = await fetch(url, {
headers: { Authorization: `Bearer ${process.env.RAILBED_SECRET_KEY}` },
}).then((r) => r.json());
const customer = page.data[0] ?? null;page = requests.get(
"https://pay.railbed.io/v1/customers",
headers={"Authorization": f"Bearer {os.environ['RAILBED_SECRET_KEY']}"},
params={"email": "maya@example.com"},
timeout=15,
).json()
customer = page["data"][0] if page["data"] else None<?php
$query = http_build_query(['email' => 'maya@example.com']);
$ch = curl_init('https://pay.railbed.io/v1/customers?' . $query);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('RAILBED_SECRET_KEY'),
],
]);
$page = json_decode(curl_exec($ch), true);
$customer = $page['data'][0] ?? null;{
"data": [
{
"id": "cus_Hc7nQ2wVz9KpT4mRb1Ye",
"object": "customer",
"email": "maya@example.com",
"name": "Maya Okafor",
"paid_orders_count": 2
}
],
"has_more": false,
"next_cursor": null
}Each item is a full customer object (trimmed here). With email, the list has at most one customer; an empty data means no customer has that email in this mode. Page through the whole list with next_cursor as on List payments. An invalid limit is 400 invalid_limit; a cursor that isn't one of your customers in this mode is 400 invalid_cursor.