Skip to main content
POST
/
v1
/
users
C#
// POST /v1/users
const stytch = require('stytch');

const client = new stytch.Client({
  project_id: '${projectId}',
  secret: '${secret}',
});

const params = {
  email: "sandbox@stytch.com",
  external_id: "my-external-id",
};

client.Users.Create(params)
  .then(resp => { console.log(resp) })
  .catch(err => { console.log(err) });
// POST /v1/users
package main

import (
"context"
"log"

"github.com/stytchauth/stytch-go/v18/stytch/consumer/stytchapi"
"github.com/stytchauth/stytch-go/v18/stytch/consumer/users"
)

func main() {
client, err := stytchapi.NewClient(
"${projectId}",
"${secret}",
)
if err != nil {
log.Fatalf("error instantiating client: %v", err)
}

params := &users.CreateParams{
Email: "sandbox@stytch.com",
ExternalID: "my-external-id",
}

resp, err := client.Users.Create(context.Background(), params)
if err != nil {
log.Fatalf("error in method call: %v", err)
}

log.Println(resp)
}
// POST /v1/users
package com.example;

import com.stytch.java.common.StytchResult;
import com.stytch.java.consumer.models.users.CreateRequest;
import com.stytch.java.consumer.StytchClient;

public class Main {
public static void main(String[] args) {
StytchClient.configure("${projectId}", "${secret}");

CreateRequest params = new CreateRequest();
params.setEmail("sandbox@stytch.com");
params.setExternalId("my-external-id");

Object result = StytchClient.getUsers().create(params);
if (result instanceof StytchResult.Success) {
System.out.println(((StytchResult.Success) result).getValue());
} else {
System.out.println(((StytchResult.Error) result).getException());
}
}
}
// POST /v1/users
package com.example

import com.stytch.java.consumer.StytchClient
import com.stytch.java.consumer.models.users.CreateRequest

fun main() {
StytchClient.configure(
projectId = "${projectId}",
secret = "${secret}",
)

when (
val result =
StytchClient.users.create(
CreateRequest(
email = "sandbox@stytch.com",
externalId = "my-external-id",
),
)
) {
is StytchResult.Success -> println(result.value)
is StytchResult.Error -> println(result.exception)
}
}
// POST /v1/users
const stytch = require('stytch');

const client = new stytch.Client({
project_id: '${projectId}',
secret: '${secret}',
});

const params = {
email: "sandbox@stytch.com",
external_id: "my-external-id",
};

client.users.create(params)
.then(resp => { console.log(resp) })
.catch(err => { console.log(err) });
$response = $client->users->create([
'email' => 'sandbox@stytch.com',
'external_id' => 'my-external-id',
]);
# POST /v1/users
from stytch import Client

client = Client(
project_id="${projectId}",
secret="${secret}",
)

resp = client.users.create(
email="sandbox@stytch.com",
external_id="my-external-id",
)

print(resp)
# frozen_string_literal: true

# POST /v1/users
require 'stytch'

client = Stytch::Client.new(
project_id: "${projectId}",
secret: "${secret}"
)

resp = client.users.create(
email: "sandbox@stytch.com",
external_id: "my-external-id"

)

puts resp
// POST /v1/users
use stytch::consumer::client::Client;
use stytch::consumer::users::CreateRequest;

fn main() {
let client = Client::new("${projectId}", "${secret}").unwrap();
let resp = client.users.create(
CreateRequest{
email: Some(String::from("sandbox@stytch.com")),
external_id: Some(String::from("my-external-id")),
..Default::default()
}
).await;
println!("The response is {:?}", resp);
}
# POST /v1/users
curl --request POST \
--url https://test.stytch.com/v1/users \
-u '${projectId}:${secret}' \
-H 'Content-Type: application/json' \
-d '{
"email": "sandbox@stytch.com",
"external_id": "my-external-id"
}'
{
  "request_id": "<string>",
  "user_id": "<string>",
  "email_id": "<string>",
  "status": "<string>",
  "phone_id": "<string>",
  "user": {
    "user_id": "<string>",
    "emails": [
      {
        "email_id": "<string>",
        "email": "<string>",
        "verified": true
      }
    ],
    "status": "<string>",
    "phone_numbers": [
      {
        "phone_id": "<string>",
        "phone_number": "<string>",
        "verified": true
      }
    ],
    "webauthn_registrations": [
      {
        "webauthn_registration_id": "<string>",
        "domain": "<string>",
        "user_agent": "<string>",
        "verified": true,
        "authenticator_type": "<string>",
        "name": "<string>"
      }
    ],
    "providers": [
      {
        "provider_type": "<string>",
        "provider_subject": "<string>",
        "profile_picture_url": "<string>",
        "locale": "<string>",
        "oauth_user_registration_id": "<string>"
      }
    ],
    "totps": [
      {
        "totp_id": "<string>",
        "verified": true
      }
    ],
    "crypto_wallets": [
      {
        "crypto_wallet_id": "<string>",
        "crypto_wallet_address": "<string>",
        "crypto_wallet_type": "<string>",
        "verified": true
      }
    ],
    "biometric_registrations": [
      {
        "biometric_registration_id": "<string>",
        "verified": true
      }
    ],
    "is_locked": true,
    "roles": [
      "<string>"
    ],
    "name": {
      "first_name": "<string>",
      "middle_name": "<string>",
      "last_name": "<string>"
    },
    "created_at": "<string>",
    "password": {
      "password_id": "<string>",
      "requires_reset": true
    },
    "trusted_metadata": {},
    "untrusted_metadata": {},
    "external_id": "<string>",
    "lock_created_at": "<string>",
    "lock_expires_at": "<string>"
  },
  "status_code": 123
}
{
"status_code": 401,
"request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
"error_type": "unauthorized_credentials",
"error_message": "Unauthorized credentials.",
"error_url": "https://stytch.com/docs/api/errors/401"
}
{
"status_code": 429,
"request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
"error_type": "too_many_requests",
"error_message": "Too many requests have been made.",
"error_url": "https://stytch.com/docs/api/errors/429"
}
{
"status_code": 500,
"request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
"error_type": "internal_server_error",
"error_message": "Oops, something seems to have gone wrong, please reach out to support@stytch.com to let us know what went wrong.",
"error_url": "https://stytch.com/docs/api/errors/500"
}
A user_id is returned in the response that can then be used to perform other operations within Stytch. An email or a phone_number is required.

Authorizations

Authorization
string
header
required

Basic authentication header of the form Basic <encoded-value>, where <encoded-value> is the base64-encoded string username:password.

Body

application/json

Request type

email
string

The email address of the end user.

name
object

The name of the user. Each field in the name object is optional.

attributes
object
phone_number
string

The phone number to use for one-time passcodes. The phone number should be in E.164 format (i.e. +1XXXXXXXXXX). You may use +10000000000 to test this endpoint, see Testing for more detail.

create_user_as_pending
boolean

Flag for whether or not to save a user as pending vs active in Stytch. Defaults to false. If true, users will be saved with status pending in Stytch's backend until authenticated. If false, users will be created as active. An example usage of a true flag would be to require users to verify their phone by entering the OTP code before creating an account for them.

trusted_metadata
object

The trusted_metadata field contains an arbitrary JSON object of application-specific data. See the Metadata reference for complete field behavior details.

untrusted_metadata
object

The untrusted_metadata field contains an arbitrary JSON object of application-specific data. Untrusted metadata can be edited by end users directly via the SDK, and cannot be used to store critical information. See the Metadata reference for complete field behavior details.

external_id
string

An identifier that can be used in API calls wherever a user_id is expected. This is a string consisting of alphanumeric, ., _, -, or | characters with a maximum length of 128 characters.

roles
string[]

Roles to explicitly assign to this User. See the RBAC guide for more information about role assignment.

Response

Successful response

request_id
string
required

Globally unique UUID that is returned with every API call. This value is important to log for debugging purposes; we may ask for this value to help identify a specific API call when helping you debug an issue.

user_id
string
required

The unique ID of the affected User.

email_id
string
required

The unique ID of a specific email address.

status
string
required

The status of the User. The possible values are pending and active.

phone_id
string
required

The unique ID for the phone number.

user
object
required

The user object affected by this API call. See the Get user endpoint for complete response field details.

status_code
integer<int32>
required

The HTTP status code of the response. Stytch follows standard HTTP response status code patterns, e.g. 2XX values equate to success, 3XX values are redirects, 4XX are client errors, and 5XX are server errors.