Skip to Content
FeaturesOrganization Provisioning

Organization Provisioning

One call stands up an organization you can hand to a user, and it is safe to retry. It creates the organization and its brand, and optionally its settings record, its first member and a credential confined to it. Your sign-up operation, your onboarding script or foir orgs provision sends it, and if the connection drops, the process restarts or the webhook is redelivered, sending it again finishes the job rather than starting a second organization.

How a retry stays safe

You choose a provision id and send it with the request. It is the idempotency key:

  • Sending the same id and the same request again resumes from the first step that did not complete.
  • Once every step has completed, sending it again does nothing and returns the same result.
  • Two calls with the same id at the same moment make one organization. The second waits for the first and then finds its work done.

Each step’s write and its completion marker commit together, in one transaction. A step marked done created exactly what it names; a step not marked done created nothing. So a retry never repeats a step that landed and never skips one that did not.

The id addresses one provision, so it is refused, as a failed precondition, when it was already used:

  • in another workspace or project,
  • by another API key, or
  • for a different request.

Use a value nobody else can produce: a UUID, or the id of the signup the organization is for. A user in the console may take up a provision an API key started, which is how the console retries one.

The steps

StepWhat it doesRequested by
Organization and brandCreates the organization, under parentId or at the top of the project, with its brand fields, in one transaction.always
Settings recordWrites the organization’s own settings record.settings
First memberMakes a user the organization’s first member, with a role: one the project has, or somebody it makes by address in the organization’s pool.firstMember
CredentialMints an API key confined to the new organization.credential

They run in that order. The credential is last so that its secret arrives on the response that completes the provision.

Provisioning an organization

curl -X POST https://rpc.foir.io/identity.v1.IdentityService/ProvisionOrganization \ -H 'Content-Type: application/json' \ -H "x-api-key: $FOIR_API_KEY" \ -d '{ "provisionId": "signup-7f3c2a9e-1b4d-4e8a-9c61-2d5e8f0a7b13", "name": "Daves Pizza", "parentId": "org_k2v9x4m7p1", "brand": { "displayName": "Daves", "primaryColor": "#c0392b", "appBaseUrl": "https://saasapp.com/daves" }, "settings": { "modelKey": "shop_settings", "data": { "currency": "GBP" } }, "firstMember": { "userId": "q8h2k5n1wz3r7d0m4c6vxe9t", "roleKey": "owner" }, "credential": { "name": "Daves storefront", "keyType": "API_KEY_TYPE_PUBLISHABLE", "grants": ["records:read"], "baselineGrants": ["records:read"] } }'

The project is the one your key is bound to. Nothing in the request names it.

Request

FieldTypeRequiredDescription
provisionIdstringyesYour id for this provision, at most 200 characters.
namestringyesThe organization’s name. Names are not unique; the organization is identified by the id the provision mints.
parentIdstringnoCreate it under this organization. Omitted creates a root.
ownPoolbooleannotrue, the organization signs its own people in, to a pool of its own, apart from its parent’s and the project’s. false, it shares the pool above it. Left out, the project’s choice for a top-level organization, and its parent’s pool for one beneath another.
usersenumnoORGANIZATION_USERS_JOINED or ORGANIZATION_USERS_EVERYONE: where somebody who signs up at it stands. Left out, the nearest organization above that chose, then the project. Its first member is a member of it either way.
joiningenumnoORGANIZATION_JOINING_INVITATION_ONLY, ORGANIZATION_JOINING_OPEN or ORGANIZATION_JOINING_REQUEST: who may join it without an invitation. Left out, the nearest organization above that chose, then the project.
brandobjectnoThe organization’s own presentation: displayName, logoUrl, primaryColor, fromName, replyTo, supportEmail, appBaseUrl, termsUrl, privacyUrl.
settings.modelKeystringwith settingsA singleton model on the organization owner plane.
settings.dataobjectnoThe record’s field values.
firstMember.userIdstringone of these twoAn existing user of the project.
firstMember.emailstringone of these twoSomebody the provision makes its first member, in the pool that serves the new organization: its own with ownPool. Whoever that pool already holds the address for is that person. Also takes users:create.
firstMember.firstName, firstMember.lastNamestringnoThe name of somebody made by email.
firstMember.roleKeystringnoThe key of the role the member holds. Left out, the member is given the role your project names for a founder.
credential.namestringwith credentialThe key’s name.
credential.keyTypeenumwith credentialWhat the key is for: API_KEY_TYPE_PUBLISHABLE, API_KEY_TYPE_SERVER or API_KEY_TYPE_ADMIN. Nothing is assumed: a credential that names no kind is refused. See Credentials.
credential.grantsstring[]with credentialWhat the key holds, in the permission catalogue’s names.
credential.baselineGrantsstring[]noWhat the key gives anyone who comes through it: a visitor with no sign-in on a publishable or a server key, and a signed-in user beneath their role. An admin key gives nobody anything. Nothing is filled in: without it the key gives a visitor nothing.

Response

{ "provision": { "provisionId": "signup-7f3c2a9e-1b4d-4e8a-9c61-2d5e8f0a7b13", "status": "ORGANIZATION_PROVISION_STATUS_COMPLETED", "steps": [ { "kind": "ORGANIZATION_PROVISION_STEP_KIND_ORGANIZATION", "state": "ORGANIZATION_PROVISION_STEP_STATE_COMPLETED", "completedAt": "2026-09-15T09:12:03.418Z" }, { "kind": "ORGANIZATION_PROVISION_STEP_KIND_SETTINGS", "state": "ORGANIZATION_PROVISION_STEP_STATE_COMPLETED", "completedAt": "2026-09-15T09:12:03.506Z" }, { "kind": "ORGANIZATION_PROVISION_STEP_KIND_FIRST_MEMBER", "state": "ORGANIZATION_PROVISION_STEP_STATE_COMPLETED", "completedAt": "2026-09-15T09:12:03.551Z" }, { "kind": "ORGANIZATION_PROVISION_STEP_KIND_CREDENTIAL", "state": "ORGANIZATION_PROVISION_STEP_STATE_COMPLETED", "completedAt": "2026-09-15T09:12:03.790Z" } ], "request": { "...": "the request as the provision recorded it" }, "organizationId": "org_q7w2e9r4t6", "settingsRecordId": "rec_3n8m1b5v", "memberId": "orgm_6c4x2z9l", "credentialId": "jx8p2m6q4w1t9r3v5y7n0c2b", "credentialKeyPrefix": "foir_pub_3kV9xQ2mT7aB" }, "credential": { "id": "jx8p2m6q4w1t9r3v5y7n0c2b", "keyType": "API_KEY_TYPE_PUBLISHABLE", "grants": ["records:read"], "baselineGrants": ["records:read"], "orgId": "org_q7w2e9r4t6", "rawKey": "foir_pub_3kV9xQ2mT7aB..." } }

A step that was not requested reads ORGANIZATION_PROVISION_STEP_STATE_SKIPPED.

The credential’s secret is returned once

credential.rawKey is on the response of the call that minted the key, and on no other. Foir stores only the key’s hash, and the provision records the key’s id and prefix, never its secret. A retry of a completed provision returns the credential without rawKey.

Store the secret when you receive it. If it was lost, rotate the key with RotateApiKey or foir api-keys rotate <credentialId>, the recovery every API key has. A retry does not mint a replacement: a webhook redelivered after the first response arrived would otherwise silently replace a secret already in use.

When a provision stops part-way

A refused step returns the refusal as the call’s error, and the provision records where it stopped. The steps before it stay done. Fix the cause, then send the same request again.

curl -X POST https://rpc.foir.io/identity.v1.IdentityService/GetOrganizationProvision \ -H 'Content-Type: application/json' \ -H "x-api-key: $FOIR_API_KEY" \ -d '{ "provisionId": "signup-7f3c2a9e-1b4d-4e8a-9c61-2d5e8f0a7b13" }'
{ "provision": { "provisionId": "signup-7f3c2a9e-1b4d-4e8a-9c61-2d5e8f0a7b13", "status": "ORGANIZATION_PROVISION_STATUS_FAILED", "steps": [ { "kind": "ORGANIZATION_PROVISION_STEP_KIND_ORGANIZATION", "state": "ORGANIZATION_PROVISION_STEP_STATE_COMPLETED", "completedAt": "2026-09-15T09:12:03.418Z" }, { "kind": "ORGANIZATION_PROVISION_STEP_KIND_SETTINGS", "state": "ORGANIZATION_PROVISION_STEP_STATE_COMPLETED", "completedAt": "2026-09-15T09:12:03.506Z" }, { "kind": "ORGANIZATION_PROVISION_STEP_KIND_FIRST_MEMBER", "state": "ORGANIZATION_PROVISION_STEP_STATE_FAILED" }, { "kind": "ORGANIZATION_PROVISION_STEP_KIND_CREDENTIAL", "state": "ORGANIZATION_PROVISION_STEP_STATE_PENDING" } ], "organizationId": "org_q7w2e9r4t6", "settingsRecordId": "rec_3n8m1b5v", "failure": { "step": "ORGANIZATION_PROVISION_STEP_KIND_FIRST_MEMBER", "code": "failed_precondition", "message": "that role is not one this project has made assignable inside an organization", "failedAt": "2026-09-15T09:12:03.549Z" } } }

GetOrganizationProvision also takes { "organizationId": "..." } to find the provision that created an organization. An organization created directly, rather than provisioned, has none and answers not found. The status read never carries a secret.

In the console, an organization created by a provision shows its steps on its detail screen, and Open provisioning shows the whole provision with a Retry button that sends the recorded request unchanged.

Who may provision

Provisioning needs organizations:create: held by an API key, given by a console user’s role, or declared by an operation. It is a permission of its own. organizations:write renames, moves, suspends and resumes the organizations there are, organizations:delete schedules one’s deletion, and whoever makes organizations need not be able to change one. Each optional step also needs what its own write needs, so a provision is never a way to write what the caller could not write directly:

StepWhat it takes
Organization and brandorganizations:create
Settings recordrecords:write on the settings model
First member, in the project’s founder rolenothing more
First member, in a role you namemembers:write and organizations:write
Credentialapikeys:write

Reading a provision needs organizations:read, or the settings read permission.

A key confined to an organization provisions only beneath it: it must name its own organization or one inside it as parentId, and a provision elsewhere, or at the top of the project, is refused. It may give the new organization its brand and its first member. It may not request a settings record, because a confined key writes no other organization’s record, and it may not request a credential, because a confined key mints nothing. It reads only the provisions inside its own subtree.

What each step requires

The organization. The parent must be one the caller can read in this project; one that cannot be read answers exactly as one that does not exist. A parent that is suspended or scheduled for deletion, itself or through an ancestor, is refused. The organization counts toward the workspace’s organization allowance, which counts every organization in the tree; a provision past the allowance stops at this step with organization limit reached and resumes once the allowance allows it.

The brand. Only the fields you send are written, onto the organization itself. Every field you leave out stays unset and is inherited from the nearest ancestor that sets it and then from the project, and it keeps inheriting when that ancestor changes. An empty string is refused: leave the field out to inherit it.

appBaseUrl is also the organization’s address: a page on it finds the organization with X-Org-Url, with the publishable key the page ships. An address another organization of the project already holds is refused, and the provision stops at this step until you send one that is free.

The settings record. The model must be a singleton on the organization owner plane (access.ownerPlane: "organization" with singleton: true), which is what makes a provision write at most one settings record however many times it is retried. The record is owned by the new organization and contained by nothing, so your project’s back office reads every organization’s, and a request standing in the organization reads its own. A provision that finds the organization already owns its record of this model records that record instead of writing a second.

The first member. Named by userId, the user must be one of the project’s users. Named by email, they are made in the pool that serves the new organization, standing at it, and a retry finds the person the first attempt made; somebody that pool already holds the address for is that person. Made without a password, they prove the address when they first come in: by a code, where the project offers one, or by choosing a password through a reset. Where the pool tells the people made for it, they are mailed a link to choose one. An organization with its own pool needs its first person named this way: somebody already in the project’s pool can’t sign in to it. The role must be one of the project’s roles, and it must give members:write, so that the organization has someone who can staff it without you.

Leave roleKey out and the member is given the role your project names for a founder (organizationSignupRole in your project settings). The project decided what a founder holds, so the caller gives nothing of its own and needs nothing beyond organizations:create. A project that names no founder role refuses the provision before anything is made, and says which setting to fill in.

Name a roleKey and you are staffing the organization. Whoever provisions gives the role, so they must hold everything it gives: a key that provisions organizations with an owner role holds what that role gives. An API key may name only a role the project has made assignable inside organizations (organizationAssignableRoles in your project settings). A user in the console, who can change that list, may name any of the project’s roles, exactly as when adding a member directly.

The credential. A project-bound key confined to the new organization, written by the two lists any key is written by. What it holds must name at least one permission and sit within the caller’s own, and may not include API key management, hooks:write or organizations:reach, which no key confined to an organization may hold. What it gives is its own list and is never filled in: a public credential provisioned without baselineGrants gives a visitor nothing. See Organizations for what a confined key can reach.

Sign-up as one operation

For a product where strangers sign themselves up, the whole of sign-up can be one operation. It creates the user, then the organization that is theirs, with its settings record and with them as its first member. Nothing in it needs an admin key: the operation declares what it does, and a run of it holds exactly that.

operations: [ { key: 'sign-up', name: 'Sign up', endpoint: 'https://example.com/api/sign-up', grants: ['users:create', 'organizations:create', 'records:write:shop_settings'], }, ],

Its handler does both with the app client and the token the run was dispatched with:

const user = await foir.users.ensure(email); const { organizationId, settingsRecordId } = await foir.organizations.provision({ provisionId: `signup-${user.id}`, name, settings: { modelKey: 'shop_settings', data: { currency: 'GBP' } }, firstMember: { userId: user.id }, });

Leave settings out, and the model’s write with it, for an organization that needs no settings record.

An organization that signs its own people in names its founder by address, so they are made in its own pool rather than the project’s, and the operation declares users:create for it:

const { organizationId } = await foir.organizations.provision({ provisionId: `signup-${email}`, name, ownPool: true, firstMember: { email, firstName }, });

The first member holds the role your project names for a founder. Name it once, in your project settings:

// foir.config.ts project: { settings: { organizationSignupRole: 'shopkeeper', // a user role of this project }, },

That is all this needs. organizationSignupEnabled is a different door: it lets any signed-in user register an organization for themselves. Leave it off and the only way in is your operation, which can check a payment, an invitation or a waiting list before it provisions anything.

Run it again and it answers the same organization. Derive provisionId from something that is the same on a retry, such as the user’s id, and a run that stopped half way is finished by the next one.

An operation that does not declare organizations:create has no such call. The data API offers a run the fields its operation declared and no others, so provisionOrganization answers Cannot query field for it, as any field it was not given does. Declaring it reaches this one call: the operation cannot list, rename, move, suspend or delete organizations, or add anyone to one.

The settings record takes the write of its model. Declare records:write:<model> beside the create. An operation that asks for settings without it is refused before anything is made, and the refusal names the write. The model must be your organization settings model, a singleton on the organization owner plane, as for any provision.

It is the one record of an organization an operation writes without running in it. The provision writes the settings of the organization it has just made, and the operation names no organization: there is no field for one. Everywhere else an organization’s own records are written by the project or from inside the organization, and an operation that names an organization as a record’s owner is refused. A founder whose role grants the model’s write can change the record once it exists.

An operation mints no credential. provisionOrganization on the data API has no way to ask for one.

From the CLI

foir orgs provision \ --provision-id signup-7f3c2a9e-1b4d-4e8a-9c61-2d5e8f0a7b13 \ --name "Daves Pizza" \ --parent org_k2v9x4m7p1 \ --display-name Daves \ --settings-model shop_settings --settings-data '{"currency":"GBP"}' \ --member q8h2k5n1wz3r7d0m4c6vxe9t --member-role owner \ --credential-name "Daves storefront" --credential-kind publishable \ --credential-grants records:read --credential-baseline-grants records:read foir orgs provision-status signup-7f3c2a9e-1b4d-4e8a-9c61-2d5e8f0a7b13

For an organization that signs its own people in, add --own-pool and name the first member with --member-email (and --member-first-name, --member-last-name) instead of --member.

Run the first command again, unchanged, to resume one that stopped. It prints the credential’s secret only on the run that minted it. See foir orgs.

From an AI assistant

The MCP server exposes foir_provision_organization, which takes the same request, and foir_get_organization_provision, which reads a provision by id or by organization.

Last updated on