> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hypersender.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Generate a WhatsApp OTP Link

> Create a WhatsApp OTP link. Users open WhatsApp and send a prefilled verification message. Your app handles the result via configured callbacks.

Call this endpoint from your server to create a WhatsApp OTP link for passwordless login. Deliver the returned `data.whatsapp_link` to the user through your app, email, or SMS. When the user opens the link, WhatsApp opens with a prefilled verification message for them to send. Your application handles the result through the success or failure callbacks you configure.

This is a **WhatsApp-only** flow. For a code that the user enters in your app, use [Request OTP Code](https://docs.hypersender.com/v2/api-reference/otp/otp-service/request-otp-code.md) instead.

> [!NOTE]
>
> You need an active Hypersender account, an API token, and an instance UUID. [Create an account](https://app.hypersender.com/register), then see the [OTP API overview](https://docs.hypersender.com/v2/api-reference/otp/otp-api-introduction.md) for the other OTP flows.

## Integration flow

1. Your backend sends an authenticated request with the recipient's WhatsApp `chatId`.
2. The API returns a unique code, expiry, status, and `whatsapp_link`.
3. Your application delivers `data.whatsapp_link` to the recipient.
4. The recipient opens the link and sends the prefilled message in WhatsApp.
5. Your application handles the configured success or failure callback and continues its own flow.

The API specification does not define a callback payload, signature, or redirect parameter. Do not grant access based only on a browser redirect or an undocumented callback field. Confirm callback behavior with your account and validate the event before completing a sensitive action.

## Request

Send the request from your backend. Keep the bearer token out of browser code and public repositories.

**`POST`** `https://app.hypersender.com/api/otp/v2/{instance}/generate-link`

```http theme={null}
Authorization: Bearer YOUR_API_TOKEN
Content-Type: application/json
```

```json theme={null}
{
  "chatId": "20123456789@c.us",
  "expires": 1800,
  "name": "YourApp",
  "message": {
    "prompt": "Give me link to login at YourApp",
    "success": "Here is your login link: {link}",
    "failed": "Login failed, please try again later.",
    "expired": "This link has expired. Please request another one."
  },
  "callback": {
    "success": "https://yourdomain.com/api/otp/success",
    "failed": "https://yourdomain.com/api/otp/failed"
  }
}
```

`chatId` is the recipient's WhatsApp chat ID. `expires` is the requested lifetime in seconds. `name` and `message` customize the verification messages. The callback URLs are optional; use publicly reachable HTTPS URLs.

## Response

On success, the response includes the OTP request details. The generated link is at `data.whatsapp_link`:

```json theme={null}
{
  "success": true,
  "message": "OTP link request created successfully",
  "data": {
    "uuid": "a0b5e14e-95da-4bd4-9e2a-071661244bef",
    "code": "RDYFQUBX",
    "chat_id": "20123456789@c.us",
    "status": "pending",
    "otp_type": "link",
    "expires_at": "2025-12-29T18:14:55+00:00",
    "created_at": "2025-12-29T17:44:55+00:00",
    "whatsapp_link": "https://wa.me/201553730661?text=Give+me+link+to+login+at+7enkesh+%5BRDYFQUBX%5D+-+DO+NOT+CHANGE+THIS+MESSAGE"
  }
}
```

## PHP example

This example uses Laravel's HTTP client. It checks the HTTP response and the documented response envelope before returning the generated WhatsApp link to the caller.

```php theme={null}
use Illuminate\Support\Facades\Http;
use RuntimeException;

$instance = config('services.hypersender.otp_instance');
$token = config('services.hypersender.otp_token');

$response = Http::withToken($token)
    ->acceptJson()
    ->post("https://app.hypersender.com/api/otp/v2/{$instance}/generate-link", [
        'chatId' => '20123456789@c.us',
        'expires' => 1800,
        'name' => 'YourApp',
        'message' => [
            'prompt' => 'Give me link to login at YourApp',
            'success' => 'Here is your login link: {link}',
            'failed' => 'Login failed, please try again later.',
            'expired' => 'This link has expired. Please request another one.',
        ],
        'callback' => [
            'success' => 'https://yourdomain.com/api/otp/success',
            'failed' => 'https://yourdomain.com/api/otp/failed',
        ],
    ]);

$response->throw();
$whatsappLink = $response->json('data.whatsapp_link');

if (! is_string($whatsappLink) || $whatsappLink === '') {
    throw new RuntimeException('The OTP API response did not include data.whatsapp_link.');
}

// Return or deliver this URL through your application.
```

Store credentials in server-side environment variables and expose them through Laravel config. The example shows link generation only; connect its result to your own delivery channel and callback handling.

## Errors and security

* If the request fails, handle the HTTP error and do not deliver a link or treat the user as verified. The published API schema does not list endpoint-specific error codes or response bodies.
* Use HTTPS callback URLs and keep the API token server-side.
* Apply request limits in your application and avoid logging OTP codes or generated links.
* The API specification does not document callback signing or a callback payload. Verify the callback contract for your account before using it to authorize access.

## Next steps

> [card] [OTP API overview](https://docs.hypersender.com/v2/api-reference/otp/otp-api-introduction.md)
>
> Compare the code and link flows.

> [card] [Generate an OTP link with Laravel](https://docs.hypersender.com/v2/packages-and-sdks/laravel/otp/generate-whatsapp-otp-link-with-laravel.md)
>
> Use the Hypersender Laravel SDK.

> [card] [Laravel SDK installation](https://docs.hypersender.com/v2/packages-and-sdks/laravel/installation.md)
>
> Install and configure the package.

> [card] [Try it in Postman](https://docs.hypersender.com/v2/api-reference/otp/how-to-generate-a-whatsapp-otp-link-in-postman.md)
>
> Follow the interactive walkthrough.

> [card] [Create your Hypersender account](https://app.hypersender.com/register)
>
> Get an API token and instance UUID to generate your first OTP link.


## OpenAPI

````yaml v2/api-reference/otp/otp-collection.json POST /{instance}/generate-link
openapi: 3.1.0
info:
  version: v2.0
  title: Hypersender OTP API Docs
  description: ''
servers:
  - url: https://app.hypersender.com/api/otp/v2
    description: Production
security:
  - Authorization: []
paths:
  /{instance}/generate-link:
    post:
      summary: Generate OTP link
      description: >-
        Generate an OTP link for the chat; returns a short code and a whatsapp
        link template.
      operationId: generateLink
      parameters:
        - $ref: '#/components/parameters/instance'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GenerateLinkRequest'
            examples:
              request:
                value:
                  chatId: 20123456789@c.us
                  expires: 1800
                  name: Hypersender
                  message:
                    prompt: Give me link to login at hypersender
                    success: 'Here is your login link: {link}'
                    failed: Login failed, please try again later.
                    expired: The link has been expired, please try another one.
                  callback:
                    success: https://yourdomain.com/callback/success
                    failed: https://yourdomain.com/callback/failed
      responses:
        '200':
          description: Link created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GenerateLinkResponse'
              examples:
                response:
                  value:
                    success: true
                    message: OTP link request created successfully
                    data:
                      uuid: a0b5e14e-95da-4bd4-9e2a-071661244bef
                      code: RDYFQUBX
                      chat_id: 20123456789@c.us
                      status: pending
                      otp_type: link
                      expires_at: '2025-12-29T18:14:55+00:00'
                      created_at: '2025-12-29T17:44:55+00:00'
                      whatsapp_link: >-
                        https://wa.me/201553730661?text=Give+me+link+to+login+at+7enkesh+%5BRDYFQUBX%5D+-+DO+NOT+CHANGE+THIS+MESSAGE
components:
  parameters:
    instance:
      name: instance
      in: path
      description: Hypersender instance UUID
      required: true
      schema:
        type: string
      example: '{{ instance_id }}'
  schemas:
    GenerateLinkRequest:
      type: object
      properties:
        chatId:
          type: string
          description: WhatsApp chat ID of the recipient (e.g. 20123456789@c.us)
        expires:
          type: integer
          description: TTL in seconds
        name:
          type: string
        message:
          type: object
          properties:
            prompt:
              type: string
            success:
              type: string
            failed:
              type: string
            expired:
              type: string
        callback:
          type: object
          properties:
            success:
              type: string
            failed:
              type: string
      required:
        - chatId
    GenerateLinkResponse:
      type: object
      properties:
        success:
          type: boolean
        message:
          type: string
        data:
          type: object
          properties:
            uuid:
              type: string
            code:
              type: string
            chat_id:
              type: string
            status:
              type: string
            otp_type:
              type: string
            expires_at:
              type: string
              format: date-time
            created_at:
              type: string
              format: date-time
            whatsapp_link:
              type: string
  securitySchemes:
    Authorization:
      type: http
      scheme: bearer

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.