> ## 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 WhatsApp OTP Link with Laravel

> Generate a WhatsApp OTP link in Laravel using the Hypersender PHP SDK.

Use the Hypersender Laravel SDK to create a WhatsApp OTP link from your application. Your backend receives the generated link and can deliver it through email, SMS, or an in-app message.

> [!NOTE]
>
> Install and configure the [Hypersender Laravel SDK](https://docs.hypersender.com/v2/packages-and-sdks/laravel/installation.md) first. You need an active WhatsApp instance and the OTP API credentials in your Laravel environment.

## Generate and deliver a link

The SDK returns Laravel's HTTP client `Response`. The API response contains the generated WhatsApp URL at `data.whatsapp_link`.

```php theme={null}
use Hypersender\Hypersender;
use Illuminate\Http\Client\RequestException;
use RuntimeException;

try {
    $response = Hypersender::otp()->generateLink(
        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.
} catch (RequestException $exception) {
    // Handle the failed API request; do not treat the user as verified.
    report($exception);
    throw $exception;
}
```

`chatId` is the recipient's WhatsApp chat ID. The SDK's `expires` parameter accepts a lifetime from 60 to 3600 seconds. Keep API credentials in server-side configuration and avoid logging the returned link or OTP code.

## What happens after generation

1. Deliver the returned `data.whatsapp_link` to the user.
2. The user opens WhatsApp and sends the prefilled message.
3. Your application handles the success or failure callback URL if you configured one.
4. Continue the login or verification flow only after your server has confirmed the verification result.

The API documentation does not define callback payload fields or a signing scheme. Confirm the callback contract for your account before using callbacks to authorize access. For the endpoint request and response examples, see [Generate WhatsApp OTP Link](https://docs.hypersender.com/v2/api-reference/otp/otp-service/generate-a-whatsapp-otp-link.md).

## Next steps

* [Install the Laravel SDK](https://docs.hypersender.com/v2/packages-and-sdks/laravel/installation.md)
* [Review the OTP API overview](https://docs.hypersender.com/v2/api-reference/otp/otp-api-introduction.md)
* [Try link generation in Postman](https://docs.hypersender.com/v2/api-reference/otp/how-to-generate-a-whatsapp-otp-link-in-postman.md)
* [Create a Hypersender account](https://app.hypersender.com/register)


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