Portal Sessions
What is a portal session?
A portal session is a one-time link you send to your customer so they can see their own bill, invoices, subscription, and usage history on a MarginFront-hosted page. Think of it like a Google Doc share link, but for billing. You generate the link on your backend with your secret API key. Your customer clicks it once. They see only their own data. The link works for one hour, then expires.Why use it?
- Let your customers see their invoices and pay (or follow up) without bothering your support team.
- Show them their usage and what they’re being billed for, so there are no surprises.
- Keep your API key safe. Your customer never sees it.
How it works
- You call
POST /v1/portal-sessionsfrom your backend. - MarginFront returns a URL like
https://portal.marginfront.com/r/mgl_abc123.... - You send that URL to your customer (email, SMS, “View my billing” button in your app, whatever fits).
- They click it. The link is used up.
- They see a MarginFront page branded with your logo and colors showing their invoices, subscription, usage, and profile.
- After one hour, they’re logged out.
- If anyone tries the same link a second time, they get a “link already used” error.
The endpoints
All four endpoints require a secret API key (mf_sk_...). Publishable keys (mf_pk_...) are rejected with 401 Unauthorized. Always call these from your backend, never from the browser.
Create a portal session
Response (
201 Created):
url to your customer. Save the id if you want to look up or revoke the session later. That’s the only field you’ll need.
curl example:
400 Bad Request: neithercustomerIdnorcustomerExternalIdwas provided.401 Unauthorized: missing API key, or you sent a publishable (mf_pk_*) key.404 Not Found: no customer in your org matches the ID you sent.
List portal sessions
The
token and url fields are NOT returned by this endpoint. Those are only returned at creation. If you lost the URL, mint a new session.
Response (200 OK):
hasMore field.
Get one portal session
token and url are NOT included. You only get those at creation time.
Returns 404 Not Found if the session doesn’t exist or belongs to another organization.
Response (200 OK):
Revoke a portal session
204 No Content on success, 404 Not Found if the session doesn’t exist.
Security notes
- Always mint links on your backend. Portal sessions require a secret key. Treat that key like a database password.
- One link, one click. The link is consumed on first open. Anyone (including the original customer) who tries it a second time gets an error.
- Tokens are only shown once. The
tokenandurlfields are returned only bycreate. Lost URLs cannot be retrieved; revoke and mint a new session. - Need to cut access early? Use the
revokeendpoint. It works immediately.

