Sessions
A Session lets one person view a fixed set of Screens for one Employer, or for one Worker. Your server creates it with POST /v1/sessions and passes its clientSecret to your frontend.
Create a fresh Session each time you render payroll, for example once per page load. Sessions are cheap, and you don’t need to store them.
Employer Sessions
Section titled “Employer Sessions”When someone at the business is looking (an owner, admin or bookkeeper), create a Session with Employer Screens and no worker:
{ "screens": ["employer-dashboard", "payroll-run-list"], "employer": { "externalId": "acct_8812", "name": "Acme Plumbing LLC" }}A few Employer Screens are about one particular Worker, such as worker-profile and onboard-worker. For those, also pass the worker they’re about:
{ "screens": ["worker-profile"], "employer": { "externalId": "acct_8812" }, "worker": { "externalId": "user_51" }}Worker Sessions
Section titled “Worker Sessions”When a Worker is looking at their own pay, create a Session with Worker Screens and the worker:
{ "screens": ["worker-payment-list", "worker-documents"], "employer": { "externalId": "acct_8812" }, "worker": { "externalId": "user_51", "firstName": "Ada", "lastName": "Lovelace" }}A Session can’t mix Employer Screens and Worker Screens.
Creating Employers and Workers
Section titled “Creating Employers and Workers”You never call a “create Employer” endpoint. The first time a Session uses an externalId, Friendly Payroll creates that Employer or Worker. So the first time, include:
- Employer:
name - Worker:
displayName, or bothfirstNameandlastName
After that, the externalId alone is enough, and any names you send are ignored. A new Employer or Worker takes a few seconds to set up. During that time the Screen shows a “Setting up payroll…” state and reports provisioning status.
externalId values are yours. Employer IDs must be unique within your account, and Worker IDs must be unique within their Employer.
Lifetime and security
Section titled “Lifetime and security”- A Session lasts 12 hours. The
expiresAtfield says exactly when it ends. The Screen keeps itself signed in until then, and after that it reports theexpiredstatus. - The
clientSecretcan be used as many times as you like until it expires, for example on a page reload. Treat it like a password. Don’t log it, and don’t put it in URLs your server records. - A Session can only ever show the Screens it was created with. If your frontend asks for any other Screen, it reports the
screen_not_allowederror. - Check permissions before you create a Session. Friendly Payroll trusts your server: whoever receives the client secret can see those Screens for that Employer or Worker.
- Your secret key (
sk_…) must never reach a browser. Only the client secret (fpcs_…) belongs in your frontend.
Errors
Section titled “Errors”Every error response has the same shape:
{ "error": { "type": "invalid_request", "message": "worker is required for these screens" }}| Status | type |
Common causes |
|---|---|---|
| 400 | invalid_request |
Unknown Screen, Employer and Worker Screens mixed, worker missing or not needed, or no name the first time an externalId is used. |
| 401 | authentication_error |
Missing or revoked secret key, or a Sandbox key sent to the Prod API (or the other way round). |
See the API reference for every field.