Sessions
Start the short-lived tokens the embedded editor, presence settings and private seals run on.
A session is a short-lived token that lets one of your users into one document in the embedded editor, into presence settings, or into the private seals they may read. Your server starts it with your secret key and hands the token to your page; the page passes it to Undertext and never sees your key. Tokens last 15 minutes, and the embed asks your getToken function for a new one before the old one runs out, so an open editor keeps working for as long as the person is allowed in. A seal reads with its token once, and asks for no more. See Embed the editor.
A session token only opens what its purpose says: the editor, presence settings or seals. It can't call the REST API.
The session object
| Attribute | Type | Description |
|---|---|---|
token | string | The token to pass to the page, starting est_. |
user | string | The user's Undertext id. |
document | string or null | The document it opens, or null for a presence session. |
purpose | string | editor, presence or seal. |
role | string or null | The role the user has in the document for this session: owner, editor, suggester or viewer. null for a presence or seal session. |
via | string or null | member when the role comes from membership, link when it comes from the document's link access. null for a presence or seal session. |
expires_at | timestamp | When the token stops being accepted, 15 minutes after it was started. |
{
"token": "est_q7Lr2VkX9pN4sT8wY3mB6cZ1",
"user": "usr_5Kq2Lm8R",
"document": "doc_8Hq2Lm4R",
"purpose": "editor",
"role": "owner",
"via": "member",
"expires_at": "2026-10-30T18:35:00Z"
}Create a session
POST /v1/sessions
Starts a session for the editor, for presence settings when you pass purpose: "presence", or for reading seals when you pass purpose: "seal".
| Parameter | Type | Description |
|---|---|---|
user | string, required | The user's Undertext id. The user must exist. |
document | string | The document to open. Required when purpose is editor. |
via | string | link to let in someone who isn't a member, with the document's link access as their role. Leave it out for members. |
purpose | string | editor (the default), presence or seal. |
email | string or null | For a seal session: the person's email, only if you've verified it. A private seal's readers are listed by email. |
group | string | Up to 200 characters of yours that the session belongs to, such as the id of the person's own sign-in session with you, so you can end them together. |
For the editor
Undertext works out the user's role when it starts the session: their member role, or with via: "link", the document's link_access. A member who comes by link keeps whichever role is higher. The role is checked again on every edit, so lowering it or removing the member takes effect in an open editor at once, whatever the token says.
curl https://api.undertext.sh/v1/sessions \
-H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" \
-H "Content-Type: application/json" \
-d '{"user": "usr_5Kq2Lm8R", "document": "doc_8Hq2Lm4R"}'{
"token": "est_q7Lr2VkX9pN4sT8wY3mB6cZ1",
"user": "usr_5Kq2Lm8R",
"document": "doc_8Hq2Lm4R",
"purpose": "editor",
"role": "owner",
"via": "member",
"expires_at": "2026-10-30T18:35:00Z"
}For someone who followed a shared link:
curl https://api.undertext.sh/v1/sessions \
-H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" \
-H "Content-Type: application/json" \
-d '{"user": "usr_9Tb3Wc1X", "document": "doc_8Hq2Lm4R", "via": "link"}'{
"token": "est_d2Hs9QmW4kR7xV1nJ6pL8tF3",
"user": "usr_9Tb3Wc1X",
"document": "doc_8Hq2Lm4R",
"purpose": "editor",
"role": "suggester",
"via": "link",
"expires_at": "2026-10-30T18:35:00Z"
}A document in the trash still opens, only to read: for its owners when it's in the trash for everyone, and for a member who put it in their own. The session's role is then viewer.
People who come by link aren't added as members. Their writing is credited to them like anyone else's, and they appear in the document's mention list while they have it open.
For presence settings
A presence session opens the window where a user adds security keys. It isn't tied to a document. Pass its token to mountPresenceSettings or openPresenceSettings in the embed API. See Set up check-ins.
curl https://api.undertext.sh/v1/sessions \
-H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" \
-H "Content-Type: application/json" \
-d '{"user": "usr_5Kq2Lm8R", "purpose": "presence"}'{
"token": "est_m5Tc8Wq1Zr6Kv3Np9Ys2Bx7H",
"user": "usr_5Kq2Lm8R",
"document": null,
"purpose": "presence",
"role": null,
"via": null,
"expires_at": "2026-10-30T18:35:00Z"
}For seals
A seal session lets a person read the private seals shared with them, on your seal page. It isn't tied to a seal or a document: Undertext lets them read a private seal if they're one of its document's members, if the document's link lets anyone open it, or if the email you vouch for is one its owners listed, by itself or as *@ and its domain. Pass only an email you've verified, as anyone who has it reads what's shared with it. Public seals need no session.
curl https://api.undertext.sh/v1/sessions \
-H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" \
-H "Content-Type: application/json" \
-d '{"user": "usr_9Tb3Wc1X", "purpose": "seal", "email": "grace@acme.com"}'{
"token": "est_r4Wd7Kp2Nx9Lq5Tz1Hm8Bc6V",
"user": "usr_9Tb3Wc1X",
"document": null,
"purpose": "seal",
"role": null,
"via": null,
"expires_at": "2026-10-30T18:35:00Z"
}Errors
| Error | When |
|---|---|
400 missing_parameter on document | purpose is editor and there's no document. |
400 invalid_parameter on group | Empty, or longer than 200 characters. |
400 invalid_parameter on email | Not an email address. |
403 no_access | The user isn't a member, and either you didn't pass via: "link" or the document's link access is restricted. |
404 user_not_found | The user doesn't exist. |
404 document_not_found | The document doesn't exist. |
409 document_trashed | The document is in its owners' trash, and the user isn't one of its owners. |
End a user's sessions
DELETE /v1/users/{user_id}/sessions
Ends a user's sessions at once: all of them, or with group, only those started in that group. Call it when someone signs out of your product, or is signed out everywhere. Their open editors lose their connection within moments and ask your page for a new token, which your server refuses once they're signed out.
| Parameter | Type | Description |
|---|---|---|
user_id | string, path, required | The user's Undertext id. |
group | string, query | Only the sessions started with this group. |
curl "https://api.undertext.sh/v1/users/usr_5Kq2Lm8R/sessions?group=sess_42" \
-X DELETE \
-H "Authorization: Bearer $UNDERTEXT_SECRET_KEY"{ "deleted": 2 }A session token lets whoever holds it write as that user until it expires. Send it only to the person it's for, over HTTPS, and don't log it. Start sessions only after your own sign-in has checked who is asking.