/
Contact usSee pricingStart building

    About B2B SaaS Authentication

    Introduction
    Stytch B2B Basics
    Integration Approaches
      Full-stack overview
      Frontend (pre-built UI)
      Frontend (headless)
      Backend
    Next.js
      Routing
      Authentication
      Sessions
    Migrations
      Overview
      Reconciling data models
      Migrating user data
      Additional migration considerations
      Zero-downtime deployment
      Defining external IDs
      Migrating from Stytch Consumer to B2B
      Exporting from Stytch
    Custom Domains
      Overview

    Authentication

    Single Sign On
    • Resources

      • Overview
        External SSO Connections
        Standalone SSO
    • Integration Guides

      • Start here
        Provider setup
        Backend integration guide
        Headless integration guide
        Pre-built UI integration guide
    OAuth
    • Resources

      • Overview
        Authentication flows
        Identity providers
        Google One Tap
        Provider setup
    • Integration Guides

      • Start here
        Backend integration
        Headless frontend integration
        Pre-built UI frontend integration
    Connected Apps
      Overview
      Getting started with the SDK
      Getting started with the API
      Client types
      OAuth scopes
    • Integration Guides

      • Integrate with an Existing Auth System
        MCP Authorization Overview
        Integrate with a remote MCP server
        Integrate with AI agents
    • Resources

      • Consent Management
        Custom Domains
        Testing Integrations
    Sessions
    • Resources

      • Overview
        JWTs vs Session Tokens
        How to use Stytch JWTs
        Custom Claims
        Custom Claim Templates
    • Integration Guides

      • Start here
        Backend integration
        Frontend integration
    Email OTP
      Overview
    Magic Links
    • Resources

      • Overview
        Email Security Scanner Protections
    • Integration Guides

      • Start here
        Backend integration
        Headless frontend integration
        Pre-built UI frontend integration
    Multi-Factor Authentication
    • Resources

      • Overview
    • Integration Guides

      • Start here
        Backend integration
        Headless frontend integration
        Pre-built UI frontend integration
    Passwords
    • Resources

      • Overview
        Strength policy
    • Integration Guides

      • Pre-built UI frontend integration
    UI components
      Overview
      Implement the Discovery flow
      Implement the Organization flow
    DFP Protected Auth
      Overview
      Setting up DFP Protected Auth
      Handling challenges
    M2M Authentication
      Authenticate an M2M Client
      Rotate client secrets
      Import M2M Clients from Auth0
    Trusted Auth Tokens
      Overview
      Getting Started with External IDPs
      Getting Started with Custom Auth Factors
    Device History
      New device notifications

    Authorization & Provisioning

    RBAC
    • Resources

      • Overview
        Stytch Resources & Roles
        Role assignment
    • Integration Guides

      • Start here
        Backend integration
        Headless frontend integration
    SCIM
    • Resources

      • Overview
        Supported actions
    • Integration Guides

      • Using Okta
        Using Microsoft Entra
    Organizations
      Managing org settings
      JIT Provisioning

    Testing

    E2E testing
    Sandbox values
Get support on SlackVisit our developer forum

Contact us

B2B SaaS Authentication

/

Guides

/

About B2B SaaS Authentication

/

Migrations

/

Defining external IDs

External IDs for members and organizations

When a member or organization is created in Stytch, they will be assigned a unique identifier that looks like a UUID. For your convenience, you may choose to additionally assign an "external ID" to a member which can then be used in any place where the Stytch member_id is expected. You can also assign an "organization external ID" to an organization which can then be used any place where the Stytch organization_id is expected.

Assigning an external ID at creation

An External IDs is a string consisting of alphanumeric, ., _, or - characters with a maximum length of 128 characters. Member external IDs must be unique across members in a given organization, but may be reused across different organizations in the same project. Organization external IDs must be unique across all organizations in the same project

When calling the Create Member you may pass in an optional external_id parameter. When calling the Create Organization you may pass in an optional organization_external_id parameter.

You may also set an external ID during a call to the Migrate Password endpoint, but only if the member does not yet exist and is created. If the member already exists, you must use the Update Member endpoint to assign or reassign the external_id.

Assigning an external ID later

If a member has already been created, you may assign it an external_id later with the Update Member endpoint. Similar to creation, pass in an external_id parameter and it will then be assigned to that member. Again, remember that external IDs must be unique within a given organization, but may be reused across different organizations in the same project.

Organizations can similarly be assigned an organization_external_id later with the Update Organization endpoint.

Updating external IDs

If you wish to change a member's external ID you may use the same Update Member endpoints listed above.

If you wish to change an organization's external ID you may use the Update Organization endpoint.

After this point, you will no longer be able to refer to that entity by its old external_id.

Using external IDs

In any endpoint that expects a member_id, you may instead choose to pass in your custom-defined external_id. For clarity, all responses from Stytch will continue to use the Stytch-defined member_id, though external_id will exist as a subfield within the Member object.

In any endpoint that expects an organization_id, you may instead choose to pass in your custom-defined organization_external_id. Similarly, all responses from Stytch will continue to use the Stytch-defined organization_id, though organization_external_id will exist as a subfield within the Organization object.

const stytch = require('stytch');

const client = new stytch.B2BClient({
  project_id: 'PROJECT_ID',
  secret: 'SECRET',
});

const params = {
  organization_id: "example-organization-external-id",
  member_id: "example-member-external-id",
};

client.organizations.members.get(params)
  .then(resp => { console.log(resp) })
  .catch(err => { console.log(err) });

Assigning an external ID at creation

Assigning an external ID later

Updating external IDs

Using external IDs