Customer sessions
When a buyer signs in to your site with your own login, your backend needs a way to read and change that buyer's Flint data, such as their orders, subscriptions, and saved cards, without being able to touch anyone else's. A customer session is that credential. Your backend creates one with your API key, then sends its secret to /v1/me, and Flint returns only the data of the customer the session names.
Flint never sees your password, identity provider, or login form. Ownership checks happen on Flint's side, so a mistake in your front end can't show one buyer another buyer's order.
Choose the credential#
| You want to | Use |
|---|---|
| Show a signed-in buyer their orders, subscriptions, cards, and Returns on your own pages | A customer session, created with POST /v1/customer-sessions |
| Send a signed-in buyer to Flint's hosted account without a second login | A customer access link |
| Take a payment in your own checkout | The checkout credential from a checkout session; see Headless storefront |
Customer sessions work whatever your customer_account.mode is. In merchant_hosted mode they run your whole account. In flint_hosted mode you can still use one for a job your own site starts, such as an email change.
How a session runs#
- Browser sends sign in with your login to Your backend
- Your backend sends POST /v1/customer-sessions with your API key to Flint
- Flint returns secret and refresh_token to Your backend
- Browser sends open order history to Your backend
- Your backend sends GET /v1/me/orders with the secret to Flint
- Flint returns this buyer's orders to Your backend
- Your backend sends POST /v1/customer-sessions/refresh when the secret expires to Flint
- Flint returns a new secret and refresh_token to Your backend
- Browser sends sign out to Your backend
- Your backend sends POST /v1/me/session/revoke with the secret to Flint
The browser talks only to your backend. Your backend holds the session and makes every Flint call.
Create a session#
After your login succeeds, call Flint with a secret API key that has customers.sessions.write, naming the buyer's Flint customer. If you don't have the buyer's customer_id yet, find or create the customer first.
curl -X POST https://api.withflintpay.com/v1/customer-sessions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "customer_id": "cus_1kmn0aExample" }'
{
"data": {
"customer_session_id": "cses_1kmn0aExample",
"customer_id": "cus_1kmn0aExample",
"status": "active",
"secret": "flint_cses_example",
"expires_at": "2026-10-28T18:00:00Z",
"refresh_token": "flint_cref_example",
"refresh_token_expires_at": "2026-11-04T17:00:00Z",
"created_at": "2026-10-28T17:00:00Z"
},
"request_id": "req_01KWM6WAHG3N9Q8T2V5XRZ7C4D"
}
A customer ID that doesn't exist in your key's merchant, mode, or sandbox returns 404 RESOURCE_NOT_FOUND with param: customer_id. A retained customer with status: deleted or deletion_processing returns 409 ACTION_NOT_ALLOWED with details[0].reason: terminal_status, resource_type: customer, and current_status naming the customer's status. No session credentials are created. Create a new customer before creating a session for a returning buyer whose customer was deleted.
The response is 201. Store these fields in your server-side session record:
| Field | What it's for |
|---|---|
customer_session_id | Names the session. Use it in the refresh Idempotency-Key and to revoke the session from your API key. |
secret | The working credential (flint_cses_). Send it as Authorization: Bearer to /v1/me. |
expires_at | When secret stops working. |
refresh_token | Single use (flint_cref_). Trade it for a new secret and refresh_token. |
refresh_token_expires_at | When the session ends and the buyer has to sign in again. |
Flint returns secret and refresh_token only from create and refresh. It never lists or returns them again, so a session whose credentials you lose can't be recovered: create a new one.
Omit capabilities for the full set of /v1/me operations, or send an explicit list to limit a session to the operations the buyer authorized. Idempotency-Key is optional here; a retry with the same key returns the same session instead of creating another, with its credentials under the one-time secret rules.
status on customer sessionTwo lifetimes, two jobs#
| Credential | Request field | Default | Range |
|---|---|---|---|
secret | expires_in_seconds | 1 hour | 300 to 86,400 seconds (5 minutes to 24 hours) |
refresh_token | refresh_expires_in_seconds | 7 days | 3,600 to 2,592,000 seconds (1 hour to 30 days) |
The defaults suit most integrations. A shorter expires_in_seconds limits how long a leaked secret works. refresh_expires_in_seconds is how long a buyer stays signed in: it is set once, when you create the session, and refreshing does not extend it. When refresh_token_expires_at passes, the buyer signs in again and you create a new session.
A secret never outlives its session. If refresh_token_expires_at comes first, expires_at is that earlier time, on create and on every refresh.
Leave a lifetime field out to use its default. A value outside its range, including 0, returns 400 INVALID_REQUEST with param naming the field. null is rejected the same way. An unrecognized field, including account_url_expires_in_seconds, returns 400 INVALID_REQUEST with detail code UNKNOWN_FIELD.
Limit what an assistant can do#
Pass capabilities when an assistant or another backend needs only part of the buyer's account. For example, an assistant that tracks orders and starts Returns can use:
{
"customer_id": "cus_1kmn0aExample",
"capabilities": ["orders.read", "returns.read", "returns.create"]
}
| Capability | Operations it permits |
|---|---|
account.read | Read the profile, email preferences, email change requests, and remembered buyers. |
account.manage | Update the profile or email preferences, change the email, and revoke remembered buyers. |
account.delete | Read and create account deletion requests. |
orders.read | Read orders, activities, tickets, payments, refunds, fulfillments, shipments, packages, invoices, and credit notes; download documents and send receipts. |
returns.read | Read Returns and return resolutions. |
returns.create | Preview, create, and cancel Returns. |
subscriptions.read | Read subscriptions and payment retries, and preview subscription changes. |
subscriptions.manage | Change subscriptions, including pausing, canceling, skipping a cycle, and updating line items or the payment method. |
payments.create | Create checkout sessions. Also required together with subscriptions.manage to resume, renew, change quantity, change plan, or retry a subscription payment. |
payment_methods.read | Read saved payment methods and Flint Wallet cards. |
payment_methods.manage | Add or delete saved payment methods and create store setups from Flint Wallet cards. |
addresses.read | Read saved addresses. |
addresses.manage | Create, update, and delete saved addresses. |
gift_cards.read | Read owned and saved gift cards and their transactions. |
gift_cards.manage | Save and remove gift cards. |
license_keys.read | List the buyer's license keys and devices. |
license_keys.manage | Resend a license key email or release a device. |
Capabilities are independent: a manage or create capability does not include the matching read capability. Every operation still checks the buyer, merchant, mode, and sandbox. A capability never permits access to another buyer's data.
Omitting the field preserves full access. An explicit [] permits only self-revocation. null, unknown names, and duplicate names return 400 INVALID_REQUEST. Explicit grants stay fixed when Flint adds capabilities. The session resource reports the granted capabilities on create, refresh, and revocation; default sessions report the full catalog. Refresh preserves an explicit grant and cannot widen it. Create a new session after the buyer authorizes a different grant.
An operation outside the grant returns 403 INSUFFICIENT_SCOPE with details[0].reason: "scope_not_granted" and missing_scopes naming the required capabilities. Refreshing does not resolve this refusal. POST /v1/me/session/revoke remains available with any capability list.
Order reads still report a pending payment's status. Payment action credentials in active_payment_attempt.pending_actions require payments.create; setup action credentials require payment_methods.manage. Flint withholds actions outside the grant, including on expanded resources and retained responses. An order-tracking assistant can tell the buyer that authentication is needed without receiving the credentials to complete it.
Keep the secret on your server#
Warning: Session secrets are server-side credentials
Handle a customer session secret exactly like an API key. Keep it out of browser code, mobile bundles, URLs, and logs. Flint has no browser credential for /v1/me: the browser calls your backend, and your backend calls Flint.
A full-access secret can read the buyer's personal data, renew a subscription or change its plan on a saved card, and request account deletion. Use an explicit capability list when the task needs less access. In the browser, any script injected into your storefront could take it. Keep customer_session_id, secret, and refresh_token in the session record on your server, keyed by your own session cookie, and never put them in the cookie itself.
Call /v1/me with the secret#
curl https://api.withflintpay.com/v1/me/orders \
-H "Authorization: Bearer flint_cses_example"
No /v1/me route accepts a customer_id: the secret already decides whose data comes back, and an ID that belongs to another buyer returns 404. The secret works only on /v1/me. Every other endpoint needs your API key.
Your backend relays the buyer's account calls to /v1/me. Relay /v1/me through your backend gives the rules and a complete Express sample, and Build your own customer account lists every route.
Refresh rotates both credentials#
When a /v1/me call returns 401 INVALID_CREDENTIAL with details[0].reason: "expired", trade the refresh token for a new pair, then resend the call. You can also refresh shortly before expires_at to avoid the failed call. Refresh takes no API key, so the path that keeps a buyer signed in never needs your secret key.
curl -X POST https://api.withflintpay.com/v1/customer-sessions/refresh \
-H "Content-Type: application/json" \
-H "Idempotency-Key: refresh-cses_1kmn0aExample" \
-d '{ "refresh_token": "flint_cref_example" }'
{
"data": {
"customer_session_id": "cses_1kmn0aExample",
"customer_id": "cus_1kmn0aExample",
"status": "active",
"secret": "flint_cses_example2",
"expires_at": "2026-10-28T19:02:00Z",
"refresh_token": "flint_cref_example2",
"refresh_token_expires_at": "2026-11-04T17:00:00Z",
"created_at": "2026-10-28T17:00:00Z"
},
"request_id": "req_01KWM6P19KJRRC7B8BBEAQQ1KB"
}
The session keeps its customer_session_id, created_at, and refresh_token_expires_at. The old secret and the refresh token you sent stop working, so save the new pair before you use it.
Send one fixed Idempotency-Key per session#
Idempotency-Key is required on refresh; without it, Flint returns 400 INVALID_REQUEST naming Idempotency-Key. Use one fixed key for each session, such as refresh- plus the customer_session_id. Flint scopes the key to the refresh token, so every request that carries the same token and key gets the same new pair for as long as Flint holds the key. That makes refresh safe from several server instances at once, and after a lost response, without a lock of your own:
- Two instances that refresh together get one rotation and the same pair.
- A request that returns
409 IDEMPOTENCY_KEY_IN_PROGRESSoverlapped another request with that token and key. Retry with the same key and token. - A retry after a timeout, with the same key and token, returns the pair the first request created.
- The next refresh sends the new token, so the same key starts a new rotation.
const FLINT = "https://api.withflintpay.com";
// session is your server-side record: { customerSessionId, secret, refreshToken }.
// Returns the new secret, or null when the buyer has to sign in again.
async function refreshCustomerSession(session) {
for (let attempt = 1; attempt <= 3; attempt++) {
const response = await fetch(`${FLINT}/v1/customer-sessions/refresh`, {
method: "POST",
headers: {
"Content-Type": "application/json",
// One fixed key per session. Flint scopes it to the refresh token.
"Idempotency-Key": `refresh-${session.customerSessionId}`,
},
body: JSON.stringify({ refresh_token: session.refreshToken }),
});
if (response.ok) {
const { data } = await response.json();
session.secret = data.secret;
session.refreshToken = data.refresh_token;
await saveSession(session); // Store the new pair before you use it.
return data.secret;
}
// 409 means another request is rotating this token; 429 and 5xx are transient.
// Retrying with the same key and token is safe in every case.
if (response.status === 409 || response.status === 429 || response.status >= 500) {
await new Promise((resolve) => setTimeout(resolve, 250 * attempt));
continue;
}
return null; // 401: the session is over.
}
return null;
}
saveSession is your own session store. When the function returns null, end your session so the buyer signs in again.
Important: Reusing a rotated refresh token revokes the session
A refresh token that was already exchanged, presented with a different Idempotency-Key, returns 401 INVALID_CREDENTIAL with details[0].reason: "revoked", and Flint revokes the session. That includes the secret the legitimate holder is using.
This is how Flint responds to a stolen refresh token: it can't tell the thief from the buyer, so it ends the session for both. Treat it as a security signal, not a transient failure. Sign the buyer out, have them sign in again, and don't retry.
Handle the failures#
On /v1/me calls:
On POST /v1/customer-sessions/refresh:
On POST /v1/customer-sessions:
Retry a /v1/me call only after a successful refresh. Every other credential failure means the same thing to your application: this buyer signs in again.
Revoke on sign-out and on suspicion#
Revoking a session ends its secret and its refresh token at once. Every /v1/me call with the secret then returns 401 INVALID_CREDENTIAL with details[0].reason: "unknown", and a refresh returns expired.
Sign the buyer out#
When the buyer clicks sign out, revoke the session with its own secret. No API key is involved:
curl -X POST https://api.withflintpay.com/v1/me/session/revoke \
-H "Authorization: Bearer flint_cses_example"
{
"data": {
"customer_session_id": "cses_1kmn0aExample",
"customer_id": "cus_1kmn0aExample",
"status": "revoked",
"expires_at": "2026-10-28T19:02:00Z",
"refresh_token_expires_at": "2026-11-04T17:00:00Z",
"created_at": "2026-10-28T17:00:00Z",
"revoked_at": "2026-10-28T18:30:00Z"
},
"request_id": "req_01KWM6WAHG3N9Q8T2V5XRZ7C4E"
}
- It works after
expires_at, so a buyer can sign out even when the secret has aged out. - Repeating it returns
200with the firstrevoked_at. - It needs the newest secret. A secret that a refresh replaced, or any unknown value, returns
401 INVALID_CREDENTIALwithdetails[0].reason: "unknown". - Send no body.
Idempotency-Keyis optional.
End your own session whatever Flint returns, so the buyer is signed out of your site.
Revoke with your API key#
For support, a password change, a closed account, or a suspected takeover, revoke from your backend with a key that has customers.sessions.write. Revoke one session by its ID:
curl -X POST https://api.withflintpay.com/v1/customer-sessions/cses_1kmn0aExample/revoke \
-H "Authorization: Bearer YOUR_API_KEY"
It returns the CustomerSession with status: "revoked" and revoked_at, and no credentials. Repeating it keeps the first revoked_at. A session that isn't in the key's environment returns 404 RESOURCE_NOT_FOUND.
To sign a buyer out everywhere, revoke every session for the customer:
curl -X POST https://api.withflintpay.com/v1/customers/cus_1kmn0aExample/sessions/revoke \
-H "Authorization: Bearer YOUR_API_KEY"
{
"data": {
"customer_id": "cus_1kmn0aExample",
"revoked_count": 2
},
"request_id": "req_01KWM6WAHG3N9Q8T2V5XRZ7C4F"
}
revoked_count counts the sessions this call revoked. Sessions that were already revoked aren't counted. An unknown customer or one outside your key's merchant, mode, or sandbox returns 404 RESOURCE_NOT_FOUND with param: customer_id. An existing customer, including a retained deleted customer, returns 200 with revoked_count: 0 when no sessions remain to revoke.
What else ends a session#
- The refresh window ends. At
refresh_token_expires_at, the buyer signs in again. - The buyer confirms an email change. Flint revokes every customer session, emailed access link, and Flint-hosted account session for the customer, including the session that confirmed the change. Create a new session after the buyer signs in with the new email. See Email change uses codes only. In
merchant_hostedmode, changing the email yourself withPATCH /v1/customers/{customer_id}keeps the buyer's sessions. - The customer is deleted. Its sessions stop working.
Customer sessions and Flint's hosted account sign-in are independent. Revoking customer sessions doesn't sign the buyer out of Flint's hosted account, and signing out there doesn't revoke your customer sessions. That matters if you run both during a migration.
Send a buyer into Flint's account#
A customer session authorizes only /v1/me. To move a buyer who is signed in on your site into Flint's hosted account without a second login, create a customer access link with the same customers.sessions.write scope:
curl -X POST https://api.withflintpay.com/v1/customers/cus_1kmn0aExample/access-links \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"return_url":"https://shop.example/account"}'
{
"data": {
"url": "https://account.withflintpay.com/auth#token=ptok_example",
"purpose": "customer_account",
"expires_at": "2026-10-28T17:15:00Z",
"return_url": "https://shop.example/account"
},
"request_id": "req_01KWM6P19KJRRC7B8BBEAQQ1KC"
}
Redirect the buyer to url at once. It works for 15 minutes and one open, on your account's host. Anyone holding it can sign in as the customer, so keep it out of stored state, logs, and email. The body is optional. Send return_url to keep a destination on your site for the browser session this link starts, until sign-out or session end. It must be a nonempty absolute HTTPS URL without credentials, up to 2,048 characters; query strings and fragments are allowed. Test mode also accepts HTTP loopback URLs. Omit it for no return destination; the response then includes return_url: null. A later sign-in by emailed code has no return URL. Use a new idempotency key if you change the destination.
The link needs Flint's hosted account. When customer_account.mode is merchant_hosted, the call returns 409 ACTION_NOT_ALLOWED with details[0].reason: merchant_hosted_customer_accounts; use a customer session and your own pages instead. Customers covers the route's other errors and its retry behavior.
Rate limits#
Calls made with a session secret count against a budget for that session and a budget shared by all of that customer's sessions, as well as your account's overall budget for the route class. A buyer who sends too many requests hits their own limit before they reach yours. When the session's own budget runs out, the 429 carries Flint-Rate-Limited-Reason: credential. When the shared customer budget runs out, the 429 carries Flint-Rate-Limited-Reason: customer.
Refresh takes no credential, so it counts against the per-IP budget for unauthenticated routes. Your backend makes every refresh, so refresh when a secret expires or is about to, not on every request.