Accept a tenant invitation
const url = 'https://api.emite.cr/v1/auth/accept-invitation';const options = { method: 'POST', headers: {'Content-Type': 'application/json'}, body: '{"email":"newhire@example.com","code":"123456","name":"Carla Soto","password":"example","legal":{"acceptances":[{"documentType":"terminos-y-condiciones","documentVersion":"3.0","documentHash":"sha256:abcdef0123456789..."}]}}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://api.emite.cr/v1/auth/accept-invitation \ --header 'Content-Type: application/json' \ --data '{ "email": "newhire@example.com", "code": "123456", "name": "Carla Soto", "password": "example", "legal": { "acceptances": [ { "documentType": "terminos-y-condiciones", "documentVersion": "3.0", "documentHash": "sha256:abcdef0123456789..." } ] } }'Three flows depending on whether the email already has an EmiteCR account:
- New user: provide
name,passwordandlegal. The endpoint creates the user (with its acceptance of the legal documents), the membership, and issues a JWT scoped to the new tenant. - Existing user, authenticated: omit
name/password; the membership is added to the caller, whose session is re-issued for the new tenant (same sign-in time, so it expires no later than before). - Existing user, NOT authenticated: responds 409
INVITE_USER_EXISTS_LOGIN_FIRST. The web redirects the recipient to/loginpreserving?code=....
The token is returned in the body and in the X-Session-Token header. When the company’s session rules do not admit the caller’s current sign-in, the membership is still created and the answer is { reauthRequired: true, reason, tenantId, role } with no token: signing in again enters the company. A request whose session belongs to another email answers 409 INVITE_AUTH_MISMATCH.
Request Bodyrequired
Section titled “Request Bodyrequired”object
The email the invitation was sent to, compared case-insensitively. When the request carries a session, it must be the email of the signed-in account (409 INVITE_AUTH_MISMATCH otherwise).
Example
newhire@example.com6-digit code from the invitation email.
Example
123456Name of the new account. Required, together with password and legal, only when the email has no EmiteCR account yet (400 INVITE_NEW_USER_REQUIRES_CREDENTIALS without it); ignored for an existing account.
Example
Carla SotoPassword for the new account (only when the email is new). A password the person chooses: 12 to 72 characters, not built on the name or the email of the account, and hard to guess (no common or leaked password, sequence, keyboard pattern or date; the same estimator the app shows under the field). Upper case, digits and symbols are neither required nor refused. Refused with 400 PASSWORD_TOO_WEAK, whose params.reason is too_short, too_long, personal_info or too_guessable. Passwords set before this rule keep working to sign in.
For a new account only: the person's acceptance of the legal documents required at signup (the Terms and the Privacy Policy, version and hash of each), written with the account in the same transaction. Required when name and password are (400 INVITE_NEW_USER_REQUIRES_ACCEPTANCE without it); ignored for an existing account.
object
One entry per document, at most 10. Every document the catalog requires at signup must be present (400 LEGAL_ACCEPTANCE_INCOMPLETE names the missing ones); an empty list is 400 LEGAL_SIGNUP_ACCEPTANCE_REQUIRED. Recorded as the person's own acceptance, with the IP, browser and instant of this request, in the same transaction that creates the account.
object
Slug of the legal document accepted, as GET /v1/legal/required-for-signup lists it: today terminos-y-condiciones (Terms and Conditions) and politica-de-privacidad (Privacy Policy). An unknown slug is 400 UNKNOWN_DOCUMENT; the Cookie Policy (politica-de-cookies) is only announced, never accepted (400 LEGAL_DOCUMENT_NOT_REQUIRED).
Example
terminos-y-condicionesThe version of the document the API serves today (its version), up to 32 characters. Any other version is 409 OUTDATED_VERSION: fetch the documents again and show the current text.
Example
3.0The SHA-256 of the exact Markdown text shown to the person: sha256: followed by 64 hex digits, copied verbatim from the hash the API serves with the document. It is the proof of which text was accepted; one that differs from the served text is 409 HASH_MISMATCH.
Example
sha256:abcdef0123456789...Responses
Section titled “Responses”The invitation was accepted. Usually a session token for the company (AcceptInvitationResponseDto); { reauthRequired: true, … } (AcceptInvitationReauthResponseDto) when the company does not admit the current sign-in.
object
Session token (JWT) scoped to the company of the invitation — send it as Authorization: Bearer <token>. Also returned in the X-Session-Token response header. For an account that was already signed in it is the same session re-issued: it keeps the original sign-in time, so it ends no later than before.
Always Bearer.
Remaining life of this token, in seconds with an explicit unit (28800s).
When this token expires.
The company the invitation belongs to — the one the token is scoped to.
The member's role in that company: the invitation's, or the one the account already held when it was a member already (the invitation is then just used up). A system role (owner, admin, billing_manager, accountant, issuer, viewer) or the slug of one of the company's custom roles (GET /v1/tenants/me/roles).
object
Always true: the invitation was accepted and the membership exists, but no token is issued — signing in again is what enters the company.
Why the company does not admit the caller's current sign-in: tenant_policy — the company's maximum session length ran out for it; sessions_revoked — an admin closed this member's sessions in the company after the person signed in.
The company the invitation belongs to.
The member's role in that company. A system role (owner, admin, billing_manager, accountant, issuer, viewer) or the slug of one of the company's custom roles (GET /v1/tenants/me/roles).
Example
{ "tokenType": "Bearer", "expiresIn": "28800s", "role": "issuer"}Headers
Section titled “Headers”The same token as accessToken. Absent from a reauthRequired answer.
When the session will be refused if nothing happens, as <deadline>:<absolute|idle>:<window> (deadline in seconds since the epoch, window in seconds): for the new token when one is issued, otherwise for the token the request came with.
INVITE_NEW_USER_REQUIRES_CREDENTIALS — new email but no name/password provided; INVITE_NEW_USER_REQUIRES_ACCEPTANCE — new email without legal.acceptances (the person's acceptance of the legal documents, written with the account).
INVITE_USER_EXISTS_LOGIN_FIRST (existing email, no JWT) or MEMBER_ALREADY_EXISTS.