login-with-whatsapp
Method: POST
Path: /auth/login/whatsapp
Tags: Authentication
Summary
Login with WhatsApp
Description
Sends an OTP to the user's WhatsApp number. Returns an otp_token to pass to the verify-otp endpoint. Set register_if_not_exists to true to auto-register new users on OTP verification. 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.loginWithWhatsApp()
Example:
// Login with WhatsApp number
const { data, error } = await sdk.auth.loginWithWhatsApp({
phone: "9876543210",
country_code: "+91",
register_if_not_exists: true
});
if (error) {
console.error("WhatsApp login failed:", error.message);
} else {
console.log("OTP sent to WhatsApp. Token:", data.otp_token);
console.log("Action:", data.otp_action); // "login" or "register"
}TypeScript Definition
"login-with-whatsapp": {
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": {
country_code?: components["schemas"]["CountryCode"];
/** @description 10 digit phone number without country code, linked with WhatsApp. */
phone: string;
/** @description When `true`, auto-registers the user if the phone number is not found. Defaults to `false` (OTP sent only to registered users). */
register_if_not_exists?: boolean;
};
};
};
responses: {
/** @description OK */
200: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": {
/** @description A descriptive message confirming the success or failure of the Login process. */
message: string;
/** @description Indicates whether the request was successful or failure (true for success, false for failure). */
success: boolean;
content: components["schemas"]["OtpContent"] & {
/** @enum {string} */
otp_action?: "login" | "register";
};
};
};
};
400: components["responses"]["AuthBadRequest"];
401: components["responses"]["Unauthorized"];
403: components["responses"]["Forbidden"];
/** @description The account does not exist or is inactive. */
404: components["responses"]["NotFound"];
500: components["responses"]["InternalServerError"];
504: components["responses"]["GatewayTimeout"];
};
};
logout: {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
requestBody?: never;
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 It is a string-based token utilized for authentication and authorization. */
access_token: string;
/** @description It is a string-based token designed for refreshing the user's access token. */
refresh_token: string;
user: components["schemas"]["LoggedOutUser"];
};
};
};
};
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"]["CountryCode"] | CountryCode |
components["schemas"]["OtpContent"] | OtpContent |
components["responses"]["AuthBadRequest"] | AuthBadRequest |
components["responses"]["Unauthorized"] | Unauthorized |
components["responses"]["Forbidden"] | Forbidden |
components["responses"]["NotFound"] | NotFound |
components["responses"]["InternalServerError"] | InternalServerError |
components["responses"]["GatewayTimeout"] | GatewayTimeout |
components["schemas"]["LoggedOutUser"] | LoggedOutUser |
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.
404
Requested resource not found
500
The request failed because of an unexpected error.
504
The request timed out.
OpenAPI Definition
{
"tags": [
"Authentication"
],
"operationId": "login-with-whatsapp",
"summary": "Login with WhatsApp",
"description": "Sends an OTP to the user's WhatsApp number. Returns an `otp_token` to pass to the verify-otp endpoint. Set `register_if_not_exists` to `true` to auto-register new users on OTP verification. 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/login-with-whatsapp",
"description": "API reference for the login-with-whatsapp operation"
},
"parameters": [
{
"$ref": "#/components/parameters/DebugMode"
}
],
"requestBody": {
"description": "",
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"phone"
],
"properties": {
"country_code": {
"$ref": "#/components/schemas/CountryCode"
},
"phone": {
"description": "10 digit phone number without country code, linked with WhatsApp.",
"type": "string",
"maxLength": 10,
"minLength": 10,
"pattern": "^\\d{10}$"
},
"register_if_not_exists": {
"description": "When `true`, auto-registers the user if the phone number is not found. Defaults to `false` (OTP sent only to registered users).",
"type": "boolean"
}
}
}
}
}
},
"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 Login process.",
"type": "string"
},
"success": {
"description": "Indicates whether the request was successful or failure (true for success, false for failure).",
"type": "boolean"
},
"content": {
"allOf": [
{
"$ref": "#/components/schemas/OtpContent"
},
{
"type": "object",
"properties": {
"otp_action": {
"type": "string",
"enum": [
"login",
"register"
]
}
}
}
]
}
}
}
}
},
"links": {
"VerifyWhatsappOtp": {
"operationId": "verify-otp",
"requestBody": {
"otp_action": "$response.body#/content/otp_action",
"otp_token": "$response.body#/content/otp_token"
},
"description": "Verify the OTP sent via WhatsApp."
}
}
},
"400": {
"$ref": "#/components/responses/AuthBadRequest"
},
"401": {
"$ref": "#/components/responses/Unauthorized"
},
"403": {
"$ref": "#/components/responses/Forbidden"
},
"404": {
"description": "The account does not exist or is inactive.",
"$ref": "#/components/responses/NotFound"
},
"500": {
"$ref": "#/components/responses/InternalServerError"
},
"504": {
"$ref": "#/components/responses/GatewayTimeout"
}
},
"security": [
{
"Authorization": []
}
],
"x-speakeasy-group": "auth",
"x-speakeasy-ignore": false,
"x-speakeasy-name-override": "loginWithWhatsapp"
}Auto-generated from OpenAPI spec and TypeScript definitions