Skip to content

generate-otp

Method: POST
Path: /auth/generate-otp

Tags: Auth

Summary

Generate OTP

Description

Generating a One-Time Password (OTP) typically involves creating a random code that is sent to a user for authentication or verification purposes.

Storefront SDK Usage

SDK Method: sdk.auth.generateOtp()

Example:

typescript
// Generate OTP for phone number
const { data, error } = await sdk.auth.generateOtp({
  phone: "9876543210",
  country_code: "+91"
});

if (error) {
  console.error("OTP generation failed:", error.message);
} else {
  console.log("OTP sent successfully");
  console.log("OTP token:", data.otp_token);
  console.log("Action:", data.otp_action);
}

TypeScript Definition

typescript
"generate-otp": {
        parameters: {
            query?: never;
            header?: {
                /** @description This param is used to enable debug mode. If debug mode is enabled, the API will return OTP as well. This is only for development and testing purposes. */
                "x-debug-mode"?: components["parameters"]["DebugMode"];
            };
            path?: never;
            cookie?: never;
        };
        requestBody: {
            content: {
                "application/json": components["schemas"]["GenerateOtpWithPhone"] | components["schemas"]["GenerateOtpWithEmail"];
            };
        };
        responses: {
            /** @description OK */
            200: {
                headers: {
                    [name: string]: unknown;
                };
                content: {
                    "application/json": {
                        /** @description A descriptive message confirming the success or failure of the operation. */
                        message: string;
                        /** @description Indicates whether the request was successful or failure (true for success, false for failure). */
                        success: boolean;
                        /** @description An object containing the response content. */
                        content: {
                            /** @description A string representing the OTP token. */
                            otp_token: string;
                            /** @description This is used for verifying OTP or using subsequent APIs call. */
                            otp_action: string;
                        };
                    };
                };
            };
            400: components["responses"]["BadRequest"];
            401: components["responses"]["Unauthorized"];
        };
    };

Component References

ReferenceResolves To
components["parameters"]["DebugMode"]DebugMode
components["schemas"]["GenerateOtpWithPhone"]GenerateOtpWithPhone
components["schemas"]["GenerateOtpWithEmail"]GenerateOtpWithEmail
components["responses"]["BadRequest"]BadRequest
components["responses"]["Unauthorized"]Unauthorized

Parameters

  • x-debug-mode (header): This param is used to enable debug mode. If debug mode is enabled, the API will return OTP as well. This is only for development and testing purposes.

Request Body

Content Types: application/json

Responses

200

OK

400

Bad request

401

Not authorized for given operation on the Resource

OpenAPI Definition

json
{
  "tags": [
    "Auth"
  ],
  "operationId": "generate-otp",
  "summary": "Generate OTP",
  "description": "Generating a One-Time Password (OTP) typically involves creating a random code that is sent to a user for authentication or verification purposes.",
  "externalDocs": {
    "url": "https://llm-docs.commercengine.io/storefront/operations/generate-otp",
    "description": "API reference for the generate-otp operation"
  },
  "parameters": [
    {
      "$ref": "#/components/parameters/DebugMode"
    }
  ],
  "requestBody": {
    "description": "",
    "required": true,
    "content": {
      "application/json": {
        "schema": {
          "oneOf": [
            {
              "$ref": "#/components/schemas/GenerateOtpWithPhone"
            },
            {
              "$ref": "#/components/schemas/GenerateOtpWithEmail"
            }
          ]
        }
      }
    }
  },
  "responses": {
    "200": {
      "description": "OK",
      "content": {
        "application/json": {
          "schema": {
            "type": "object",
            "required": [
              "message",
              "success",
              "content"
            ],
            "properties": {
              "message": {
                "description": "A descriptive message confirming the success or failure of the operation.",
                "type": "string"
              },
              "success": {
                "description": "Indicates whether the request was successful or failure (true for success, false for failure).",
                "type": "boolean"
              },
              "content": {
                "description": "An object containing the response content.",
                "properties": {
                  "otp_token": {
                    "description": "A string representing the OTP token.",
                    "type": "string"
                  },
                  "otp_action": {
                    "description": "This is used for verifying OTP or using subsequent APIs call.",
                    "type": "string"
                  }
                },
                "required": [
                  "otp_token",
                  "otp_action"
                ],
                "type": "object"
              }
            }
          }
        }
      }
    },
    "400": {
      "$ref": "#/components/responses/BadRequest"
    },
    "401": {
      "$ref": "#/components/responses/Unauthorized"
    }
  },
  "security": [
    {
      "Authorization": []
    }
  ],
  "x-speakeasy-group": "auth",
  "x-speakeasy-ignore": false,
  "x-speakeasy-name-override": "generateOtp"
}

Auto-generated from OpenAPI spec and TypeScript definitions

Last updated: