Stytch TOTP API

The TOTP API from Stytch — 4 operation(s) for totp.

OpenAPI Specification

stytch-totp-api-openapi.yml Raw ↑
openapi: 3.0.3
info:
  title: Stytch B2B Authentication Application TOTP 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: TOTP
paths:
  /v1/totps:
    post:
      summary: Create
      operationId: api_totp_v1_Create
      tags:
      - TOTP
      description: Create a new TOTP instance for a user. The user can use the authenticator application of their choice to scan the QR code or enter the secret.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/api_totp_v1_CreateRequest'
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/api_totp_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/totps\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.TOTPs.Create(params)\n  .then(resp => { console.log(resp) })\n  .catch(err => { console.log(err) });"
      - lang: go
        label: Go
        source: "// POST /v1/totps\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/totps\"\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 := &totps.CreateParams{\n\t\tUserID: \"${userId}\",\n\t}\n\n\tresp, err := client.TOTPs.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/totps\npackage com.example;\n\nimport com.stytch.java.common.StytchResult;\nimport com.stytch.java.consumer.models.totps.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.setUserId(\"${userId}\");\n\n        Object result = StytchClient.getTOTPs().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/totps\npackage com.example\n\nimport com.stytch.java.consumer.StytchClient\nimport com.stytch.java.consumer.models.totps.CreateRequest\n\nfun main() {\n    StytchClient.configure(\n        projectId = \"${projectId}\",\n        secret = \"${secret}\",\n    )\n\n    when (\n        val result =\n            StytchClient.totps.create(\n                CreateRequest(\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: "// POST /v1/totps\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.totps.create(params)\n  .then(resp => { console.log(resp) })\n  .catch(err => { console.log(err) });"
      - lang: php
        label: PHP
        source: "$response = $client->totps->create([\n    'user_id' => '${userId}',\n]);"
      - lang: python
        label: Python
        source: "# POST /v1/totps\nfrom stytch import Client\n\nclient = Client(\n    project_id=\"${projectId}\",\n    secret=\"${secret}\",\n)\n\nresp = client.totps.create(\n    user_id=\"${userId}\",\n)\n\nprint(resp)\n"
      - lang: ruby
        label: Ruby
        source: "# POST /v1/totps\nrequire 'stytch'\n\nclient = Stytch::Client.new(\n  project_id: \"${projectId}\",\n  secret: \"${secret}\"\n)\n\nresp = client.totps.create(\n  user_id: \"${userId}\"\n  \n)\n\nputs resp"
      - lang: rust
        label: Rust
        source: "// POST /v1/totps\nuse stytch::consumer::client::Client;\nuse stytch::consumer::totps::CreateRequest;\n\nfn main() {\n    let client = Client::new(\"${projectId}\", \"${secret}\").unwrap();\n    let resp = client.totps.create(\n        CreateRequest{\n            user_id: \"${userId}\",\n            ..Default::default()\n        }\n    ).await;\n    println!(\"The response is {:?}\", resp);\n}"
      - lang: bash
        label: cURL
        source: "# POST /v1/totps\ncurl --request POST \\\n  --url https://test.stytch.com/v1/totps \\\n  -u '${projectId}:${secret}' \\\n  -H 'Content-Type: application/json' \\\n  -d '{\n    \"user_id\": \"${userId}\"\n  }'"
  /v1/totps/authenticate:
    post:
      summary: Authenticate
      operationId: api_totp_v1_Authenticate
      tags:
      - TOTP
      description: Authenticate a TOTP code entered by a user.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/api_totp_v1_AuthenticateRequest'
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/api_totp_v1_AuthenticateResponse'
        '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/totps/authenticate\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  totp_code: \"${exampleTotpCode}\",\n  session_duration_minutes: 60,\n};\n\nclient.TOTPs.Authenticate(params)\n  .then(resp => { console.log(resp) })\n  .catch(err => { console.log(err) });"
      - lang: go
        label: Go
        source: "// POST /v1/totps/authenticate\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/totps\"\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 := &totps.AuthenticateParams{\n\t\tUserID:                 \"${userId}\",\n\t\tTOTPCode:               \"${exampleTotpCode}\",\n\t\tSessionDurationMinutes: 60,\n\t}\n\n\tresp, err := client.TOTPs.Authenticate(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/totps/authenticate\npackage com.example;\n\nimport com.stytch.java.common.StytchResult;\nimport com.stytch.java.consumer.models.totps.AuthenticateRequest;\nimport com.stytch.java.consumer.StytchClient;\n\npublic class Main {\n    public static void main(String[] args) {\n        StytchClient.configure(\"${projectId}\", \"${secret}\");\n\n        AuthenticateRequest params = new AuthenticateRequest();\n        params.setUserId(\"${userId}\");\n        params.setTOTPCode(\"${exampleTotpCode}\");\n        params.setSessionDurationMinutes(60);\n\n        Object result = StytchClient.getTOTPs().authenticate(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/totps/authenticate\npackage com.example\n\nimport com.stytch.java.consumer.StytchClient\nimport com.stytch.java.consumer.models.totps.AuthenticateRequest\n\nfun main() {\n    StytchClient.configure(\n        projectId = \"${projectId}\",\n        secret = \"${secret}\",\n    )\n\n    when (\n        val result =\n            StytchClient.totps.authenticate(\n                AuthenticateRequest(\n                    userId = \"${userId}\",\n                    totpCode = \"${exampleTotpCode}\",\n                    sessionDurationMinutes = 60,\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/totps/authenticate\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  totp_code: \"${exampleTotpCode}\",\n  session_duration_minutes: 60,\n};\n\nclient.totps.authenticate(params)\n  .then(resp => { console.log(resp) })\n  .catch(err => { console.log(err) });"
      - lang: php
        label: PHP
        source: "$response = $client->totps->authenticate([\n    'user_id' => '${userId}',\n    'totp_code' => '${exampleTotpCode}',\n    'session_duration_minutes' => 60,\n]);"
      - lang: python
        label: Python
        source: "# POST /v1/totps/authenticate\nfrom stytch import Client\n\nclient = Client(\n    project_id=\"${projectId}\",\n    secret=\"${secret}\",\n)\n\nresp = client.totps.authenticate(\n    user_id=\"${userId}\",\n    totp_code=\"${exampleTotpCode}\",\n    session_duration_minutes=60,\n)\n\nprint(resp)\n"
      - lang: ruby
        label: Ruby
        source: "# POST /v1/totps/authenticate\nrequire 'stytch'\n\nclient = Stytch::Client.new(\n  project_id: \"${projectId}\",\n  secret: \"${secret}\"\n)\n\nresp = client.totps.authenticate(\n  user_id: \"${userId}\",\n  totp_code: \"${exampleTotpCode}\",\n  session_duration_minutes: 60\n  \n)\n\nputs resp"
      - lang: rust
        label: Rust
        source: "// POST /v1/totps/authenticate\nuse stytch::consumer::client::Client;\nuse stytch::consumer::totps::AuthenticateRequest;\n\nfn main() {\n    let client = Client::new(\"${projectId}\", \"${secret}\").unwrap();\n    let resp = client.totps.authenticate(\n        AuthenticateRequest{\n            user_id: \"${userId}\",\n            totp_code: \"${exampleTotpCode}\",\n            session_duration_minutes: 60,\n            ..Default::default()\n        }\n    ).await;\n    println!(\"The response is {:?}\", resp);\n}"
      - lang: bash
        label: cURL
        source: "# POST /v1/totps/authenticate\ncurl --request POST \\\n  --url https://test.stytch.com/v1/totps/authenticate \\\n  -u '${projectId}:${secret}' \\\n  -H 'Content-Type: application/json' \\\n  -d '{\n    \"user_id\": \"${userId}\",\n    \"totp_code\": \"${exampleTotpCode}\",\n    \"session_duration_minutes\": 60\n  }'"
  /v1/totps/recovery_codes:
    post:
      summary: Recoverycodes
      operationId: api_totp_v1_RecoveryCodes
      tags:
      - TOTP
      description: Retrieve the recovery codes for a TOTP instance tied to a User.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/api_totp_v1_RecoveryCodesRequest'
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/api_totp_v1_RecoveryCodesResponse'
        '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/totps/recovery_codes\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.TOTPs.RecoveryCodes(params)\n  .then(resp => { console.log(resp) })\n  .catch(err => { console.log(err) });"
      - lang: go
        label: Go
        source: "// POST /v1/totps/recovery_codes\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/totps\"\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 := &totps.RecoveryCodesParams{\n\t\tUserID: \"${userId}\",\n\t}\n\n\tresp, err := client.TOTPs.RecoveryCodes(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/totps/recovery_codes\npackage com.example;\n\nimport com.stytch.java.common.StytchResult;\nimport com.stytch.java.consumer.models.totps.RecoveryCodesRequest;\nimport com.stytch.java.consumer.StytchClient;\n\npublic class Main {\n    public static void main(String[] args) {\n        StytchClient.configure(\"${projectId}\", \"${secret}\");\n\n        RecoveryCodesRequest params = new RecoveryCodesRequest();\n        params.setUserId(\"${userId}\");\n\n        Object result = StytchClient.getTOTPs().recoveryCodes(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/totps/recovery_codes\npackage com.example\n\nimport com.stytch.java.consumer.StytchClient\nimport com.stytch.java.consumer.models.totps.RecoveryCodesRequest\n\nfun main() {\n    StytchClient.configure(\n        projectId = \"${projectId}\",\n        secret = \"${secret}\",\n    )\n\n    when (\n        val result =\n            StytchClient.totps.recoveryCodes(\n                RecoveryCodesRequest(\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: "// POST /v1/totps/recovery_codes\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.totps.recoveryCodes(params)\n  .then(resp => { console.log(resp) })\n  .catch(err => { console.log(err) });"
      - lang: php
        label: PHP
        source: "$response = $client->totps->recovery_codes([\n    'user_id' => '${userId}',\n]);"
      - lang: python
        label: Python
        source: "# POST /v1/totps/recovery_codes\nfrom stytch import Client\n\nclient = Client(\n    project_id=\"${projectId}\",\n    secret=\"${secret}\",\n)\n\nresp = client.totps.recovery_codes(\n    user_id=\"${userId}\",\n)\n\nprint(resp)\n"
      - lang: ruby
        label: Ruby
        source: "# POST /v1/totps/recovery_codes\nrequire 'stytch'\n\nclient = Stytch::Client.new(\n  project_id: \"${projectId}\",\n  secret: \"${secret}\"\n)\n\nresp = client.totps.recovery_codes(\n  user_id: \"${userId}\"\n  \n)\n\nputs resp"
      - lang: rust
        label: Rust
        source: "// POST /v1/totps/recovery_codes\nuse stytch::consumer::client::Client;\nuse stytch::consumer::totps::RecoveryCodesRequest;\n\nfn main() {\n    let client = Client::new(\"${projectId}\", \"${secret}\").unwrap();\n    let resp = client.totps.recovery_codes(\n        RecoveryCodesRequest{\n            user_id: \"${userId}\",\n            ..Default::default()\n        }\n    ).await;\n    println!(\"The response is {:?}\", resp);\n}"
      - lang: bash
        label: cURL
        source: "# POST /v1/totps/recovery_codes\ncurl --request POST \\\n  --url https://test.stytch.com/v1/totps/recovery_codes \\\n  -u '${projectId}:${secret}' \\\n  -H 'Content-Type: application/json' \\\n  -d '{\n    \"user_id\": \"${userId}\"\n  }'"
  /v1/totps/recover:
    post:
      summary: Recover
      operationId: api_totp_v1_Recover
      tags:
      - TOTP
      description: Authenticate a recovery code for a TOTP instance.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/api_totp_v1_RecoverRequest'
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/api_totp_v1_RecoverResponse'
        '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/totps/recover\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  recovery_code: \"${exampleTotpRecoveryCode}\",\n  session_duration_minutes: 60,\n};\n\nclient.TOTPs.Recover(params)\n  .then(resp => { console.log(resp) })\n  .catch(err => { console.log(err) });"
      - lang: go
        label: Go
        source: "// POST /v1/totps/recover\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/totps\"\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 := &totps.RecoverParams{\n\t\tUserID:                 \"${userId}\",\n\t\tRecoveryCode:           \"${exampleTotpRecoveryCode}\",\n\t\tSessionDurationMinutes: 60,\n\t}\n\n\tresp, err := client.TOTPs.Recover(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/totps/recover\npackage com.example;\n\nimport com.stytch.java.common.StytchResult;\nimport com.stytch.java.consumer.models.totps.RecoverRequest;\nimport com.stytch.java.consumer.StytchClient;\n\npublic class Main {\n    public static void main(String[] args) {\n        StytchClient.configure(\"${projectId}\", \"${secret}\");\n\n        RecoverRequest params = new RecoverRequest();\n        params.setUserId(\"${userId}\");\n        params.setRecoveryCode(\"${exampleTotpRecoveryCode}\");\n        params.setSessionDurationMinutes(60);\n\n        Object result = StytchClient.getTOTPs().recover(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/totps/recover\npackage com.example\n\nimport com.stytch.java.consumer.StytchClient\nimport com.stytch.java.consumer.models.totps.RecoverRequest\n\nfun main() {\n    StytchClient.configure(\n        projectId = \"${projectId}\",\n        secret = \"${secret}\",\n    )\n\n    when (\n        val result =\n            StytchClient.totps.recover(\n                RecoverRequest(\n                    userId = \"${userId}\",\n                    recoveryCode = \"${exampleTotpRecoveryCode}\",\n                    sessionDurationMinutes = 60,\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/totps/recover\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  recovery_code: \"${exampleTotpRecoveryCode}\",\n  session_duration_minutes: 60,\n};\n\nclient.totps.recover(params)\n  .then(resp => { console.log(resp) })\n  .catch(err => { console.log(err) });"
      - lang: php
        label: PHP
        source: "$response = $client->totps->recover([\n    'user_id' => '${userId}',\n    'recovery_code' => '${exampleTotpRecoveryCode}',\n    'session_duration_minutes' => 60,\n]);"
      - lang: python
        label: Python
        source: "# POST /v1/totps/recover\nfrom stytch import Client\n\nclient = Client(\n    project_id=\"${projectId}\",\n    secret=\"${secret}\",\n)\n\nresp = client.totps.recover(\n    user_id=\"${userId}\",\n    recovery_code=\"${exampleTotpRecoveryCode}\",\n    session_duration_minutes=60,\n)\n\nprint(resp)\n"
      - lang: ruby
        label: Ruby
        source: "# POST /v1/totps/recover\nrequire 'stytch'\n\nclient = Stytch::Client.new(\n  project_id: \"${projectId}\",\n  secret: \"${secret}\"\n)\n\nresp = client.totps.recover(\n  user_id: \"${userId}\",\n  recovery_code: \"${exampleTotpRecoveryCode}\",\n  session_duration_minutes: 60\n  \n)\n\nputs resp"
      - lang: rust
        label: Rust
        source: "// POST /v1/totps/recover\nuse stytch::consumer::client::Client;\nuse stytch::consumer::totps::RecoverRequest;\n\nfn main() {\n    let client = Client::new(\"${projectId}\", \"${secret}\").unwrap();\n    let resp = client.totps.recover(\n        RecoverRequest{\n            user_id: \"${userId}\",\n            recovery_code: \"${exampleTotpRecoveryCode}\",\n            session_duration_minutes: 60,\n            ..Default::default()\n        }\n    ).await;\n    println!(\"The response is {:?}\", resp);\n}"
      - lang: bash
        label: cURL
        source: "# POST /v1/totps/recover\ncurl --request POST \\\n  --url https://test.stytch.com/v1/totps/recover \\\n  -u '${projectId}:${secret}' \\\n  -H 'Content-Type: application/json' \\\n  -d '{\n    \"user_id\": \"${userId}\",\n    \"recovery_code\": \"${exampleTotpRecoveryCode}\",\n    \"session_duration_minutes\": 60\n  }'"
components:
  schemas:
    api_session_v1_SlackOAuthFactor:
      type: object
      properties:
        id:
          type: string
          description: The unique ID of an OAuth registration.
        provider_subject:
          type: string
          description: The unique identifier for the User within a given OAuth provider. Also commonly called the `sub` or "Subject field" in OAuth protocols.
        email_id:
          type: string
          description: The globally unique UUID of the Member's email.
      required:
      - id
      - provider_subject
    api_session_v1_HubspotOAuthFactor:
      type: object
      properties:
        id:
          type: string
          description: The unique ID of an OAuth registration.
        provider_subject:
          type: string
          description: The unique identifier for the User within a given OAuth provider. Also commonly called the `sub` or "Subject field" in OAuth protocols.
        email_id:
          type: string
          description: The globally unique UUID of the Member's email.
      required:
      - id
      - provider_subject
    api_totp_v1_CreateResponse:
      type: object
      properties:
        request_id:
          type: string
          description: 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.
        totp_id:
          type: string
          description: The unique ID for a TOTP instance.
        secret:
          type: string
          description: The TOTP secret key shared between the authenticator app and the server used to generate TOTP codes.
        qr_code:
          type: string
          description: The QR code image encoded in base64.
        recovery_codes:
          type: array
          items:
            type: string
          description: The recovery codes used to authenticate the user without an authenticator app.
        user:
          $ref: '#/components/schemas/api_user_v1_User'
          description: The `user` object affected by this API call. See the [Get user endpoint](https://stytch.com/docs/api/get-user) for complete response field details.
        user_id:
          type: string
          description: The unique ID of the affected User.
        status_code:
          type: integer
          format: int32
          description: 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.
      required:
      - request_id
      - totp_id
      - secret
      - qr_code
      - recovery_codes
      - user
      - user_id
      - status_code
    api_session_v1_TwitchOAuthFactor:
      type: object
      properties:
        id:
          type: string
        provider_subject:
          type: string
        email_id:
          type: string
      required:
      - id
      - provider_subject
    api_session_v1_EmbeddableMagicLinkFactor:
      type: object
      properties:
        embedded_id:
          type: string
      required:
      - embedded_id
    api_session_v1_EmailFactor:
      type: object
      properties:
        email_id:
          type: string
          description: The globally unique UUID of the Member's email.
        email_address:
          type: string
          description: The email address of the Member.
      required:
      - email_id
      - email_address
    api_device_history_v1_DeviceInfo:
      type: object
      properties:
        visitor_id:
          type: string
          description: The `visitor_id` (a unique identifier) of the user's device. See the [Device Fingerprinting documentation](https://stytch.com/docs/fraud/guides/device-fingerprinting/fingerprints) for more details on the `visitor_id`.
        visitor_id_details:
          $ref: '#/components/schemas/api_device_history_v1_DeviceAttributeDetails'
          description: Information about the `visitor_id`.
        ip_address:
          type: string
          description: The IP address of the user's device.
        ip_address_details:
          $ref: '#/components/schemas/api_device_history_v1_DeviceAttributeDetails'
          description: Information about the `ip_address`.
        ip_geo_city:
          type: string
          description: The city where the IP address is located.
        ip_geo_region:
          type: string
          description: The region where the IP address is located.


# --- truncated at 32 KB (77 KB total) ---
# Full source: https://raw.githubusercontent.com/api-evangelist/stytch/refs/heads/main/openapi/stytch-totp-api-openapi.yml