Skip to main content
POST
/
{instance}
/
request-code
Request OTP code
curl --request POST \
  --url https://app.hypersender.com/api/otp/v2/{instance}/request-code \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "chatId": "[email protected]",
  "length": 6,
  "useLetter": false,
  "useNumber": true,
  "allCapital": false,
  "name": "hypersender",
  "expires": 1800
}
'
{
  "success": true,
  "message": "OTP code generated and message queued successfully",
  "data": {
    "uuid": "a0b5df6a-b491-4190-80a5-38d85a2a4836",
    "chat_id": "[email protected]",
    "code": "439713",
    "status": "pending",
    "otp_type": "code",
    "expires_at": "2025-12-29T18:09:38+00:00",
    "created_at": "2025-12-29T17:39:38+00:00"
  }
}

Overview

Generate a one-time password (OTP) code and automatically send it to a WhatsApp user. This endpoint is perfect for implementing two-factor authentication, phone verification, or secure login systems.

How It Works

  1. Send a request with the recipient’s chatId and OTP configuration
  2. The system generates a random code based on your specifications
  3. The code is stored with an expiration time
  4. A message containing the code is queued to be sent to the user
  5. You receive the code details to verify later

Parameters

chatId (required)

The WhatsApp chat ID of the recipient (e.g., [email protected])

length

The length of the OTP code. Default is 6 characters.

useLetter

Include letters in the code generation. Default is false.

useNumber

Include numbers in the code generation. Default is true.

allCapital

Make all letters uppercase when useLetter is true. Default is false.

name

The name to display in the message template (e.g., your app or service name).

expires

Time-to-live (TTL) in seconds before the code expires. Default is 1800 seconds (30 minutes).

Showcase Example Message

Request OTP Code

Response

The response includes:
  • uuid: Unique identifier for this OTP request
  • chat_id: The recipient’s chat ID
  • code: The generated OTP code (store this securely if needed)
  • status: Current status (pending, sent, validated, or expired)
  • otp_type: Type of OTP (always code for this endpoint)
  • expires_at: ISO 8601 timestamp when the code expires
  • created_at: ISO 8601 timestamp when the code was created

View All of your OTP Requests

Request OTP Code

Usage Example

use Illuminate\Support\Facades\Http;

$response = Http::withToken('YOUR_API_TOKEN')
    ->post('https://app.hypersender.com/api/otp/v2/{instance}/request-code', [
        'chatId' => '[email protected]',
        'length' => 6,
        'useLetter' => false,
        'useNumber' => true,
        'name' => 'YourAppName',
        'expires' => 1800,
    ]);

$result = $response->json();
$otpData = $result['data'] ?? null;

// Example: log or store uuid and status
info('OTP uuid: ' . ($otpData['uuid'] ?? ''));

Next Steps

After generating the code:
  1. The user will receive the OTP via WhatsApp
  2. User enters the code in your application
  3. Use the Validate OTP Code endpoint to verify the code
  4. Check the uuid to track the verification status
Set an appropriate expires time based on your security requirements. Shorter expiration times (5-10 minutes) provide better security but may frustrate users if they need more time to complete the verification.

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Path Parameters

instance
string
required

Hypersender instance UUID

Body

application/json
chatId
string
required

WhatsApp chat id (e.g. [email protected])

length
integer

Length of the code

useLetter
boolean
useNumber
boolean
allCapital
boolean
name
string

Name to show in messages

expires
integer

TTL in seconds

Response

200 - application/json

Successful response

success
boolean
message
string
data
object