generate-otp
Method: POST
Path: /auth/generate-otp
Tags: Authentication
Summary
Generate OTP
Description
Generates and sends an OTP for authentication or verification. Returns an otp_token. Pass reset-password codes to reset-password; pass other codes to verify-otp. Asking again while the code is valid sends the same code (and otp_token); once it has expired or been used up, a new one.
Storefront SDK Usage
SDK Method: sdk.auth.generateOtp()
Example:
// Generate OTP for phone number
const { data, error } = await sdk.auth.generateOtp({
channel: "sms",
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
"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;
content: components["schemas"]["OtpChallenge"];
};
};
};
400: components["responses"]["AuthBadRequest"];
401: components["responses"]["Unauthorized"];
403: components["responses"]["Forbidden"];
500: components["responses"]["InternalServerError"];
504: components["responses"]["GatewayTimeout"];
};
};Component References
| Reference | Resolves To |
|---|---|
components["parameters"]["DebugMode"] | DebugMode |
components["schemas"]["GenerateOtpWithPhone"] | GenerateOtpWithPhone |
components["schemas"]["GenerateOtpWithEmail"] | GenerateOtpWithEmail |
components["schemas"]["OtpChallenge"] | OtpChallenge |
components["responses"]["AuthBadRequest"] | AuthBadRequest |
components["responses"]["Unauthorized"] | Unauthorized |
components["responses"]["Forbidden"] | Forbidden |
components["responses"]["InternalServerError"] | InternalServerError |
components["responses"]["GatewayTimeout"] | GatewayTimeout |
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
Authentication failed. Codes include token-required, token-expired and token_not_valid for an invalid or expired token.
403
Access denied. token-required requires an authenticated session; permission-denied means the caller cannot access this resource. On POS, session-expired requires signing in again.
500
The request failed because of an unexpected error.
504
The request timed out.
OpenAPI Definition
{
"tags": [
"Authentication"
],
"operationId": "generate-otp",
"summary": "Generate OTP",
"description": "Generates and sends an OTP for authentication or verification. Returns an `otp_token`. Pass `reset-password` codes to `reset-password`; pass other codes to `verify-otp`. Asking again while the code is valid sends the same code (and `otp_token`); once it has expired or been used up, a new one.",
"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": {
"$ref": "#/components/schemas/OtpChallenge"
}
}
}
}
}
},
"400": {
"$ref": "#/components/responses/AuthBadRequest"
},
"401": {
"$ref": "#/components/responses/Unauthorized"
},
"403": {
"$ref": "#/components/responses/Forbidden"
},
"500": {
"$ref": "#/components/responses/InternalServerError"
},
"504": {
"$ref": "#/components/responses/GatewayTimeout"
}
},
"security": [
{
"Authorization": []
}
],
"x-speakeasy-group": "auth",
"x-speakeasy-ignore": false,
"x-speakeasy-name-override": "generateOtp"
}Auto-generated from OpenAPI spec and TypeScript definitions