openapi: 3.0.3
info:
title: Stytch B2B Authentication Application User API
version: 2.0.0
description: Stytch's B2B API for multi-tenant authentication. Supports Organizations, Members, SSO (SAML/OIDC), Magic Links, OTP, OAuth, Discovery, Sessions, B2B RBAC, SCIM, TOTP, Recovery Codes, Passwords, Impersonation, and the B2B IDP.
contact:
name: Stytch
url: https://stytch.com/docs
license:
name: Proprietary
servers:
- url: https://api.stytch.com
description: Production
- url: https://test.stytch.com
description: Test
tags:
- name: User
paths:
/v1/users:
post:
summary: Create
operationId: api_user_v1_Create
tags:
- User
description: Add a User to Stytch. 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.
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/api_user_v1_CreateRequest'
responses:
'200':
description: Successful response
content:
application/json:
schema:
$ref: '#/components/schemas/api_user_v1_CreateResponse'
'400':
description: Bad request
'401':
description: Unauthorized
content:
application/json:
example:
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
'429':
description: Too Many Requests
content:
application/json:
example:
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
'500':
description: Internal server error
content:
application/json:
example:
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
x-code-samples:
- lang: csharp
label: C#
source: "// POST /v1/users\nconst stytch = require('stytch');\n\nconst client = new stytch.Client({\n project_id: '${projectId}',\n secret: '${secret}',\n});\n\nconst params = {\n email: \"${email}\",\n external_id: \"my-external-id\",\n};\n\nclient.Users.Create(params)\n .then(resp => { console.log(resp) })\n .catch(err => { console.log(err) });"
- lang: go
label: Go
source: "// POST /v1/users\npackage main\n\nimport (\n\t\"context\"\n\t\"log\"\n\n\t\"github.com/stytchauth/stytch-go/v17/stytch/consumer/stytchapi\"\n\t\"github.com/stytchauth/stytch-go/v17/stytch/consumer/users\"\n)\n\nfunc main() {\n\tclient, err := stytchapi.NewClient(\n\t\t\"${projectId}\",\n\t\t\"${secret}\",\n\t)\n\tif err != nil {\n\t\tlog.Fatalf(\"error instantiating client: %v\", err)\n\t}\n\n\tparams := &users.CreateParams{\n\t\tEmail: \"${email}\",\n\t\tExternalID: \"my-external-id\",\n\t}\n\n\tresp, err := client.Users.Create(context.Background(), params)\n\tif err != nil {\n\t\tlog.Fatalf(\"error in method call: %v\", err)\n\t}\n\n\tlog.Println(resp)\n}\n"
- lang: java
label: Java
source: "// POST /v1/users\npackage com.example;\n\nimport com.stytch.java.common.StytchResult;\nimport com.stytch.java.consumer.models.users.CreateRequest;\nimport com.stytch.java.consumer.StytchClient;\n\npublic class Main {\n public static void main(String[] args) {\n StytchClient.configure(\"${projectId}\", \"${secret}\");\n\n CreateRequest params = new CreateRequest();\n params.setEmail(\"${email}\");\n params.setExternalId(\"my-external-id\");\n\n Object result = StytchClient.getUsers().create(params);\n if (result instanceof StytchResult.Success) {\n System.out.println(((StytchResult.Success) result).getValue());\n } else {\n System.out.println(((StytchResult.Error) result).getException());\n }\n }\n}"
- lang: kotlin
label: Kotlin
source: "// POST /v1/users\npackage com.example\n\nimport com.stytch.java.consumer.StytchClient\nimport com.stytch.java.consumer.models.users.CreateRequest\n\nfun main() {\n StytchClient.configure(\n projectId = \"${projectId}\",\n secret = \"${secret}\",\n )\n\n when (\n val result =\n StytchClient.users.create(\n CreateRequest(\n email = \"${email}\",\n externalId = \"my-external-id\",\n ),\n )\n ) {\n is StytchResult.Success -> println(result.value)\n is StytchResult.Error -> println(result.exception)\n }\n}\n"
- lang: javascript
label: Node.js
source: "// POST /v1/users\nconst stytch = require('stytch');\n\nconst client = new stytch.Client({\n project_id: '${projectId}',\n secret: '${secret}',\n});\n\nconst params = {\n email: \"${email}\",\n external_id: \"my-external-id\",\n};\n\nclient.users.create(params)\n .then(resp => { console.log(resp) })\n .catch(err => { console.log(err) });"
- lang: php
label: PHP
source: "$response = $client->users->create([\n 'email' => '${email}',\n 'external_id' => 'my-external-id',\n]);"
- lang: python
label: Python
source: "# POST /v1/users\nfrom stytch import Client\n\nclient = Client(\n project_id=\"${projectId}\",\n secret=\"${secret}\",\n)\n\nresp = client.users.create(\n email=\"${email}\",\n external_id=\"my-external-id\",\n)\n\nprint(resp)\n"
- lang: ruby
label: Ruby
source: "# POST /v1/users\nrequire 'stytch'\n\nclient = Stytch::Client.new(\n project_id: \"${projectId}\",\n secret: \"${secret}\"\n)\n\nresp = client.users.create(\n email: \"${email}\",\n external_id: \"my-external-id\"\n \n)\n\nputs resp"
- lang: rust
label: Rust
source: "// POST /v1/users\nuse stytch::consumer::client::Client;\nuse stytch::consumer::users::CreateRequest;\n\nfn main() {\n let client = Client::new(\"${projectId}\", \"${secret}\").unwrap();\n let resp = client.users.create(\n CreateRequest{\n email: Some(String::from(\"${email}\")),\n external_id: Some(String::from(\"my-external-id\")),\n ..Default::default()\n }\n ).await;\n println!(\"The response is {:?}\", resp);\n}"
- lang: bash
label: cURL
source: "# POST /v1/users\ncurl --request POST \\\n --url https://test.stytch.com/v1/users \\\n -u '${projectId}:${secret}' \\\n -H 'Content-Type: application/json' \\\n -d '{\n \"email\": \"${email}\",\n \"external_id\": \"my-external-id\"\n }'"
/v1/users/{user_id}:
get:
summary: Get
operationId: api_user_v1_Get
tags:
- User
description: Get information about a specific User.
parameters:
- name: user_id
in: path
required: true
schema:
type: string
description: The unique ID of a specific User. You may use an `external_id` here if one is set for the user.
description: The unique ID of a specific User. You may use an `external_id` here if one is set for the user.
responses:
'200':
description: Successful response
content:
application/json:
schema:
$ref: '#/components/schemas/api_user_v1_GetResponse'
'400':
description: Bad request
'401':
description: Unauthorized
content:
application/json:
example:
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
'429':
description: Too Many Requests
content:
application/json:
example:
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
'500':
description: Internal server error
content:
application/json:
example:
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
x-code-samples:
- lang: csharp
label: C#
source: "// GET /v1/users/{user_id}\nconst stytch = require('stytch');\n\nconst client = new stytch.Client({\n project_id: '${projectId}',\n secret: '${secret}',\n});\n\nconst params = {\n user_id: \"${userId}\",\n};\n\nclient.Users.Get(params)\n .then(resp => { console.log(resp) })\n .catch(err => { console.log(err) });"
- lang: go
label: Go
source: "// GET /v1/users/{user_id}\npackage main\n\nimport (\n\t\"context\"\n\t\"log\"\n\n\t\"github.com/stytchauth/stytch-go/v17/stytch/consumer/stytchapi\"\n\t\"github.com/stytchauth/stytch-go/v17/stytch/consumer/users\"\n)\n\nfunc main() {\n\tclient, err := stytchapi.NewClient(\n\t\t\"${projectId}\",\n\t\t\"${secret}\",\n\t)\n\tif err != nil {\n\t\tlog.Fatalf(\"error instantiating client: %v\", err)\n\t}\n\n\tparams := &users.GetParams{\n\t\tUserID: \"${userId}\",\n\t}\n\n\tresp, err := client.Users.Get(context.Background(), params)\n\tif err != nil {\n\t\tlog.Fatalf(\"error in method call: %v\", err)\n\t}\n\n\tlog.Println(resp)\n}\n"
- lang: java
label: Java
source: "// GET /v1/users/{user_id}\npackage com.example;\n\nimport com.stytch.java.common.StytchResult;\nimport com.stytch.java.consumer.models.users.GetRequest;\nimport com.stytch.java.consumer.StytchClient;\n\npublic class Main {\n public static void main(String[] args) {\n StytchClient.configure(\"${projectId}\", \"${secret}\");\n\n GetRequest params = new GetRequest();\n params.setUserId(\"${userId}\");\n\n Object result = StytchClient.getUsers().get(params);\n if (result instanceof StytchResult.Success) {\n System.out.println(((StytchResult.Success) result).getValue());\n } else {\n System.out.println(((StytchResult.Error) result).getException());\n }\n }\n}"
- lang: kotlin
label: Kotlin
source: "// GET /v1/users/{user_id}\npackage com.example\n\nimport com.stytch.java.consumer.StytchClient\nimport com.stytch.java.consumer.models.users.GetRequest\n\nfun main() {\n StytchClient.configure(\n projectId = \"${projectId}\",\n secret = \"${secret}\",\n )\n\n when (\n val result =\n StytchClient.users.get(\n GetRequest(\n userId = \"${userId}\",\n ),\n )\n ) {\n is StytchResult.Success -> println(result.value)\n is StytchResult.Error -> println(result.exception)\n }\n}\n"
- lang: javascript
label: Node.js
source: "// GET /v1/users/{user_id}\nconst stytch = require('stytch');\n\nconst client = new stytch.Client({\n project_id: '${projectId}',\n secret: '${secret}',\n});\n\nconst params = {\n user_id: \"${userId}\",\n};\n\nclient.users.get(params)\n .then(resp => { console.log(resp) })\n .catch(err => { console.log(err) });"
- lang: php
label: PHP
source: "$response = $client->users->get([\n 'user_id' => '${userId}',\n]);"
- lang: python
label: Python
source: "# GET /v1/users/{user_id}\nfrom stytch import Client\n\nclient = Client(\n project_id=\"${projectId}\",\n secret=\"${secret}\",\n)\n\nresp = client.users.get(\n user_id=\"${userId}\",\n)\n\nprint(resp)\n"
- lang: ruby
label: Ruby
source: "# GET /v1/users/{user_id}\nrequire 'stytch'\n\nclient = Stytch::Client.new(\n project_id: \"${projectId}\",\n secret: \"${secret}\"\n)\n\nresp = client.users.get(\n user_id: \"${userId}\"\n \n)\n\nputs resp"
- lang: rust
label: Rust
source: "// GET /v1/users/{user_id}\nuse stytch::consumer::client::Client;\nuse stytch::consumer::users::GetRequest;\n\nfn main() {\n let client = Client::new(\"${projectId}\", \"${secret}\").unwrap();\n let resp = client.users.get(\n GetRequest{\n user_id: \"${userId}\",\n ..Default::default()\n }\n ).await;\n println!(\"The response is {:?}\", resp);\n}"
- lang: bash
label: cURL
source: "# GET /v1/users/{user_id}\ncurl --request GET \\\n --url https://test.stytch.com/v1/users/${userId} \\\n -u '${projectId}:${secret}' \\\n -H 'Content-Type: application/json'"
put:
summary: Update
operationId: api_user_v1_Update
tags:
- User
description: 'Update a User''s attributes.
**Note:** In order to add a new email address or phone number to an existing User object, pass the new email address or phone number into the respective `/send` endpoint for the authentication method of your choice. If you specify the existing User''s `user_id` while calling the `/send` endpoint, the new, unverified email address or phone number will be added to the existing User object. If the user successfully authenticates within 5 minutes of the `/send` request, the new email address or phone number will be marked as verified and remain permanently on the existing Stytch User. Otherwise, it will be removed from the User object, and any subsequent login requests using that phone number will create a new User. We require this process to guard against an account takeover vulnerability.'
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/api_user_v1_UpdateRequest'
parameters:
- name: user_id
in: path
required: true
schema:
type: string
description: The unique ID of a specific User. You may use an `external_id` here if one is set for the user.
description: The unique ID of a specific User. You may use an `external_id` here if one is set for the user.
responses:
'200':
description: Successful response
content:
application/json:
schema:
$ref: '#/components/schemas/api_user_v1_UpdateResponse'
'400':
description: Bad request
'401':
description: Unauthorized
content:
application/json:
example:
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
'429':
description: Too Many Requests
content:
application/json:
example:
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
'500':
description: Internal server error
content:
application/json:
example:
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
delete:
summary: Delete
operationId: api_user_v1_Delete
tags:
- User
description: Delete a User from Stytch.
parameters:
- name: user_id
in: path
required: true
schema:
type: string
description: The unique ID of a specific User. You may use an `external_id` here if one is set for the user.
description: The unique ID of a specific User. You may use an `external_id` here if one is set for the user.
responses:
'200':
description: Successful response
content:
application/json:
schema:
$ref: '#/components/schemas/api_user_v1_DeleteResponse'
'400':
description: Bad request
'401':
description: Unauthorized
content:
application/json:
example:
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
'429':
description: Too Many Requests
content:
application/json:
example:
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
'500':
description: Internal server error
content:
application/json:
example:
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
x-code-samples:
- lang: csharp
label: C#
source: "// DELETE /v1/users/{user_id}\nconst stytch = require('stytch');\n\nconst client = new stytch.Client({\n project_id: '${projectId}',\n secret: '${secret}',\n});\n\nconst params = {\n user_id: \"${userId}\",\n};\n\nclient.Users.Delete(params)\n .then(resp => { console.log(resp) })\n .catch(err => { console.log(err) });"
- lang: go
label: Go
source: "// DELETE /v1/users/{user_id}\npackage main\n\nimport (\n\t\"context\"\n\t\"log\"\n\n\t\"github.com/stytchauth/stytch-go/v17/stytch/consumer/stytchapi\"\n\t\"github.com/stytchauth/stytch-go/v17/stytch/consumer/users\"\n)\n\nfunc main() {\n\tclient, err := stytchapi.NewClient(\n\t\t\"${projectId}\",\n\t\t\"${secret}\",\n\t)\n\tif err != nil {\n\t\tlog.Fatalf(\"error instantiating client: %v\", err)\n\t}\n\n\tparams := &users.DeleteParams{\n\t\tUserID: \"${userId}\",\n\t}\n\n\tresp, err := client.Users.Delete(context.Background(), params)\n\tif err != nil {\n\t\tlog.Fatalf(\"error in method call: %v\", err)\n\t}\n\n\tlog.Println(resp)\n}\n"
- lang: java
label: Java
source: "// DELETE /v1/users/{user_id}\npackage com.example;\n\nimport com.stytch.java.common.StytchResult;\nimport com.stytch.java.consumer.models.users.DeleteRequest;\nimport com.stytch.java.consumer.StytchClient;\n\npublic class Main {\n public static void main(String[] args) {\n StytchClient.configure(\"${projectId}\", \"${secret}\");\n\n DeleteRequest params = new DeleteRequest();\n params.setUserId(\"${userId}\");\n\n Object result = StytchClient.getUsers().delete(params);\n if (result instanceof StytchResult.Success) {\n System.out.println(((StytchResult.Success) result).getValue());\n } else {\n System.out.println(((StytchResult.Error) result).getException());\n }\n }\n}"
- lang: kotlin
label: Kotlin
source: "// DELETE /v1/users/{user_id}\npackage com.example\n\nimport com.stytch.java.consumer.StytchClient\nimport com.stytch.java.consumer.models.users.DeleteRequest\n\nfun main() {\n StytchClient.configure(\n projectId = \"${projectId}\",\n secret = \"${secret}\",\n )\n\n when (\n val result =\n StytchClient.users.delete(\n DeleteRequest(\n userId = \"${userId}\",\n ),\n )\n ) {\n is StytchResult.Success -> println(result.value)\n is StytchResult.Error -> println(result.exception)\n }\n}\n"
- lang: javascript
label: Node.js
source: "// DELETE /v1/users/{user_id}\nconst stytch = require('stytch');\n\nconst client = new stytch.Client({\n project_id: '${projectId}',\n secret: '${secret}',\n});\n\nconst params = {\n user_id: \"${userId}\",\n};\n\nclient.users.delete(params)\n .then(resp => { console.log(resp) })\n .catch(err => { console.log(err) });"
- lang: php
label: PHP
source: "$response = $client->users->delete([\n 'user_id' => '${userId}',\n]);"
- lang: python
label: Python
source: "# DELETE /v1/users/{user_id}\nfrom stytch import Client\n\nclient = Client(\n project_id=\"${projectId}\",\n secret=\"${secret}\",\n)\n\nresp = client.users.delete(\n user_id=\"${userId}\",\n)\n\nprint(resp)\n"
- lang: ruby
label: Ruby
source: "# DELETE /v1/users/{user_id}\nrequire 'stytch'\n\nclient = Stytch::Client.new(\n project_id: \"${projectId}\",\n secret: \"${secret}\"\n)\n\nresp = client.users.delete(\n user_id: \"${userId}\"\n \n)\n\nputs resp"
- lang: rust
label: Rust
source: "// DELETE /v1/users/{user_id}\nuse stytch::consumer::client::Client;\nuse stytch::consumer::users::DeleteRequest;\n\nfn main() {\n let client = Client::new(\"${projectId}\", \"${secret}\").unwrap();\n let resp = client.users.delete(\n DeleteRequest{\n user_id: \"${userId}\",\n ..Default::default()\n }\n ).await;\n println!(\"The response is {:?}\", resp);\n}"
- lang: bash
label: cURL
source: "# DELETE /v1/users/{user_id}\ncurl --request DELETE \\\n --url https://test.stytch.com/v1/users/${userId} \\\n -u '${projectId}:${secret}' \\\n -H 'Content-Type: application/json'"
/v1/users/search:
post:
summary: Search
operationId: api_user_v1_Search
tags:
- User
description: '
**Warning**: This endpoint is not recommended for use in login flows. Scaling issues may occur, as search performance may vary from ~150 milliseconds to 9 seconds depending on query complexity and rate limits are set to 150 requests/minute.
Search for Users within your Stytch Project.
Use the `query` object to filter by different fields. See the `query.operands.filter_value` documentation below for a list of available filters.
### Export all User data
Submit an empty `query` in your Search Users request to return all of your Stytch Project''s Users.
[This Github repository](https://github.com/stytchauth/stytch-node-export-users) contains a utility that leverages the Search Users endpoint to export all of your User data to a CSV or JSON file.'
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/api_user_v1_SearchRequest'
responses:
'200':
description: Successful response
content:
application/json:
schema:
$ref: '#/components/schemas/api_user_v1_SearchResponse'
'400':
description: Bad request
'401':
description: Unauthorized
content:
application/json:
example:
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
'429':
description: Too Many Requests
content:
application/json:
example:
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
'500':
description: Internal server error
content:
application/json:
example:
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
/v1/users/{user_id}/exchange_primary_factor:
put:
summary: Exchangeprimaryfactor
operationId: api_user_v1_ExchangePrimaryFactor
tags:
- User
description: 'Exchange a user''s email address or phone number for another.
Must pass either an `email_address` or a `phone_number`.
This endpoint only works if the user has exactly one factor. You are able to exchange the type of factor for another as well, i.e. exchange an `email_address` for a `phone_number`.
Use this endpoint with caution as it performs an admin level action.'
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/api_user_v1_ExchangePrimaryFactorRequest'
parameters:
- name: user_id
in: path
required: true
schema:
type: string
description: The unique ID of a specific User. You may use an `external_id` here if one is set for the user.
description: The unique ID of a specific User. You may use an `external_id` here if one is set for the user.
responses:
'200':
description: Successful response
content:
application/json:
schema:
$ref: '#/components/schemas/api_user_v1_ExchangePrimaryFactorResponse'
'400':
description: Bad request
'401':
description: Unauthorized
content:
application/json:
example:
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
'429':
description: Too Many Requests
content:
application/json:
example:
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
'500':
description: Internal server error
content:
application/json:
example:
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
x-code-samples:
- lang: csharp
label: C#
source: "// PUT /v1/users/{user_id}/exchange_primary_factor\nconst stytch = require('stytch');\n\nconst client = new stytch.Client({\n project_id: '${projectId}',\n secret: '${secret}',\n});\n\nconst params = {\n user_id: \"${userId}\",\n};\n\nclient.Users.ExchangePrimaryFactor(params)\n .then(resp => { console.log(resp) })\n .catch(err => { console.log(err) });"
- lang: go
label: Go
source: "// PUT /v1/users/{user_id}/exchange_primary_factor\npackage main\n\nimport (\n\t\"context\"\n\t\"log\"\n\n\t\"github.com/stytchauth/stytch-go/v17/stytch/consumer/stytchapi\"\n\t\"github.com/stytchauth/stytch-go/v17/stytch/consumer/users\"\n)\n\nfunc main() {\n\tclient, err := stytchapi.NewClient(\n\t\t\"${projectId}\",\n\t\t\"${secret}\",\n\t)\n\tif err != nil {\n\t\tlog.Fatalf(\"error instantiating client: %v\", err)\n\t}\n\n\tparams := &users.ExchangePrimaryFactorParams{\n\t\tUserID: \"${userId}\",\n\t}\n\n\tresp, err := client.Users.ExchangePrimaryFactor(context.Background(), params)\n\tif err != nil {\n\t\tlog.Fatalf(\"error in method call: %v\", err)\n\t}\n\n\tlog.Println(resp)\n}\n"
- lang: java
label: Java
source: "// PUT /v1/users/{user_id}/exchange_primary_factor\npackage com.example;\n\nimport com.stytch.java.common.StytchResult;\nimport com.stytch.java.consumer.models.users.ExchangePrimaryFactorRequest;\nimport com.stytch.java.consumer.StytchClient;\n\npublic class Main {\n public static void main(String[] args) {\n StytchClient.configure(\"${projectId}\", \"${secret}\");\n\n ExchangePrimaryFactorRequest params = new ExchangePrimaryFactorRequest();\n params.setUserId(\"${userId}\");\n\n Object result = StytchClient.getUsers().exchangePrimaryFactor(params);\n if (result instanceof StytchResult.Success) {\n System.out.println(((StytchResult.Success) result).getValue());\n } else {\n System.out.println(((StytchResult.Error) result).getException());\n }\n }\n}"
- lang: kotlin
label: Kotlin
source: "// PUT /v1/users/{user_id}/exchange_primary_factor\npackage com.example\n\nimport com.stytch.java.consumer.StytchClient\nimport com.stytch.java.consumer.models.users.ExchangePrimaryFactorRequest\n\nfun main() {\n StytchClient.configure(\n projectId = \"${projectId}\",\n secret = \"${secret}\",\n )\n\n when (\n val result =\n StytchClient.users.exchangePrimaryFactor(\n ExchangePrimaryFactorRequest(\n userId = \"${userId}\",\n ),\n )\n ) {\n is StytchResult.Success -> println(result.value)\n is StytchResult.Error -> println(result.exception)\n }\n}\n"
- lang: javascript
label: Node.js
source: "// PUT /v1/users/{user_id}/exchange_primary_factor\nconst stytch = require('stytch');\n\nconst client = new stytch.Client({\n project_id: '${projectId}',\n secret: '${secret}',\n});\n\nconst params = {\n user_id: \"${userId}\",\n};\n\nclient.users.exchangePrimaryFactor(params)\n .then(resp => { console.log(resp) })\n .catch(err => { console.log(err) });"
- lang: php
label: PHP
source: "$response = $client->users->exchange_primary_factor([\n 'user_id' => '${userId}',\n]);"
- lang: python
label: Python
source: "# PUT /v1/users/{user_id}/exchange_primary_factor\nfrom stytch import Client\n\nclient = Client(\n project_id=\"${projectId}\",\n secret=\"${secret}\",\n)\n\nresp = client.users.exchange_primary_factor(\n user_id=\"${userId}\",\n)\n\nprint(resp)\n"
- lang: ruby
label: Ruby
source: "# PUT /v1/users/{user_id}/exchange_primary_factor\nrequire 'stytch'\n\nclient = Stytch::Client.new(\n project_id: \"${projectId}\",\n secret: \"${secret}\"\n)\n\nresp = client
# --- truncated at 32 KB (148 KB total) ---
# Full source: https://raw.githubusercontent.com/api-evangelist/stytch/refs/heads/main/openapi/stytch-user-api-openapi.yml