Skip to main content
import { useStytchB2BClient } from '@stytch/react/b2b';

export const CreateOrganization = () => {
  const stytch = useStytchB2BClient();
  const [organizationName, setOrganizationName] = useState('');

  const createOrganization = async () => {
    await stytch.discovery.organizations.create({
      organization_name: organizationName,
      session_duration_minutes: 60,
    });
  };

  return (
    <>
      <input type="text" placeholder="Organization Name" value={organizationName} onChange={(e) => setOrganizationName(e.target.value)} />
      <button onClick={createOrganization}>Create Organization</button>
    </>
  );
};
{
  "request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
  "status_code": 200,
  "member_id": "member-test-32fc5024-9c09-4da3-bd2e-c9ce4da9375f",
  "session_token": "mZAYn5aLEqKUlZ_Ad9U_fWr38GaAQ1oFAhT8ds245v7Q",
  "session_jwt": "eyJ...",
  "intermediate_session_token": "",
  "member_authenticated": true,
  "mfa_required": null,
  "primary_required": null,
    "member_session": {...},
    "member": {...},
    "organization": {...}
}
The discovery.organizations.create method wraps the create Organization via Discovery endpoint.
Before using this method, enable in the Frontend SDK page.
The Member created by this endpoint will automatically be granted the stytch_admin Role. See the RBAC guide for more details on this Role. This method will fail if there is no present. If this method succeeds and the Member is not required to complete MFA, the Member will be logged in, granted an active session, and the session cookies will be minted and stored in the browser. If this method succeeds and MFA is required, the intermediate session token will be stored in the browser as a cookie.

Parameters

session_duration_minutes
number
required
Set the session lifetime to be this many minutes from now. This will return both an opaque session_token and session_jwt for this session, which will automatically be stored in the browser cookies. The session_jwt will have a fixed lifetime of five minutes regardless of the underlying session duration, and will be automatically refreshed by the SDK in the background over time.This value must be a minimum of 5 and may not exceed the maximum session duration minutes value set in the Stytch Dashboard.A successful authentication will continue to extend the session this many minutes.
organization_name
string
The name of the Organization.If the name is not specified, a default name will be created based on the email used to initiate the discovery flow:
  • If the email domain is a common email provider such as gmail.com, or if the email is a .edu email, the organization name will be generated based on the name portion of the email.
  • Otherwise, the organization name will be generated based on the email domain.
organization_slub
string
The unique URL slug of the Organization. A minimum of two characters is required. The slug only accepts alphanumeric characters and the following reserved characters: - . _ ~.If the slug is not specified, a default slug will be created using the same logic as organization_name.
organization_logo_url
string
The image URL of the Organization logo.
email_jit_provisioning
object
The authentication setting that controls how a new Member can be provisioned by authenticating via Email Magic Link or OAuth. The accepted values are:
  • RESTRICTED – only new Members with verified emails that comply with email_allowed_domains can be provisioned upon authentication via Email Magic Link or OAuth.
  • NOT_ALLOWED – the default setting, disables JIT provisioning via Email Magic Link and OAuth.
email_invites
string
The authentication setting that controls how a new Member can be invited to an organization by email. The accepted values are:
  • ALL_ALLOWED – any new Member can be invited to join via email.
  • RESTRICTED – only new Members with verified emails that comply with email_allowed_domains can be invited via email.
  • NOT_ALLOWED – disable email invites.
email_allowed_domains
string
An array of email domains that allow invites or JIT provisioning for new Members. This list is enforced when either email_invites or email_jit_provisioning is set to RESTRICTED. Common domains such as gmail.com are not allowed. See the full list.
sso_jit_provisioning
string
The authentication setting that controls the JIT provisioning of Members when authenticating via SSO. The accepted values are:
  • ALL_ALLOWED – the default setting, new Members will be automatically provisioned upon successful authentication via any of the Organization’s sso_active_connections.
  • RESTRICTED – only new Members with SSO logins that comply with sso_jit_provisioning_allowed_connections can be provisioned upon authentication.
  • NOT_ALLOWED – disable JIT provisioning via SSO.
auth_methods
string
The setting that controls which authentication methods can be used by Members of an Organization. The accepted values are:
  • ALL_ALLOWED – the default setting which allows all authentication methods to be used.
  • RESTRICTED – only methods that comply with allowed_auth_methods can be used for authentication. This setting does not apply to Members with is_breakglass set to true.
allowed_auth_methods
string
An array of allowed authentication methods. This list is enforced when auth_methods is set to RESTRICTED. The list’s accepted values are: sso, magic_link, email_otp, password, google_oauth, microsoft_oauth, slack_oauth, github_oauth, and hubspot_oauth.
mfa_policy
string
The setting that controls the MFA policy for all Members in the Organization. The accepted values are:
  • REQUIRED_FOR_ALL – All Members within the Organization will be required to complete MFA every time they wish to log in. However, any active Session that existed prior to this setting change will remain valid.
  • OPTIONAL – The default value. The Organization does not require MFA by default for all Members. Members will be required to complete MFA only if their mfa_enrolled status is set to true.

Response

member_id
string
The unique ID of the Member.
member_session
object
The new Stytch Session.
member
object
The Member object of the signed-in Member.
organization
object
The Organization object of the Organization the Member has signed into.
session_jwt
string
The JWT for the new Stytch Session.
If the project is configured to use HttpOnly cookies, this field will always be an empty string.
session_token
string
The secret token for the new Stytch Session.
If the project is configured to use HttpOnly cookies, this field will always be an empty string.
member_device
object
If Protected Auth is enabled and returned fingerprinting results, this field will contain information about the member’s device attributes.
member_authenticated
boolean
Indicates whether the Member is fully authenticated. If false, the Member needs to complete an MFA step to log in to the Organization.
intermediate_session_token
string
The intermediate_session_token that should be passed into a secondary authentication endpoint, such as OTP authenticate, in order to receive a member session. The intermediate_session_token can also be used with discovery endpoints to join a different organization or create a new organization.If the member is fully authenticated, this field will be an empty string.
If the project is configured to use HttpOnly cookies, this field will always be an empty string.
primary_required
object | null
The types of primary authentication required.
mfa_required
object | null
The types of secondary authentication required to join the Organization.
member_device
object
If Protected Auth is enabled and returned fingerprinting results, this field will contain information about the member’s device attributes.