> ## 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.

# WhatsApp OTP Link with Node.js

> Create a WhatsApp OTP link from Node.js: the user taps it, sends the prefilled code from WhatsApp, and is verified with no code to type. Built on the OTP API.

Use the Hypersender Node 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 Node SDK](https://docs.hypersender.com/v2/packages-and-sdks/node/installation.md) first. You need an active WhatsApp instance and the OTP API credentials in your environment.

## Generate and deliver a link

The SDK returns the parsed, typed response. The generated WhatsApp URL is at `data.whatsappLink`.

```typescript theme={null}
import { Hypersender } from "hypersender-node";
import { HypersenderError } from "hypersender-node/models/errors";

try {
  const result = await Hypersender.otp().generateLink({
    chatId: "20123456789@c.us",
    expires: 1800,
    name: "YourApp",
    message: {
      prompt: "Send me my YourApp link",
      success: "Here is your 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",
    },
  });

  const whatsappLink = result.data?.whatsappLink;

  if (!whatsappLink) {
    throw new Error("The OTP API response did not include data.whatsappLink.");
  }

  // Return or deliver this URL through your application.
} catch (error) {
  if (error instanceof HypersenderError) {
    // Handle the failed API request; do not treat the user as verified.
    console.error(`OTP link request failed with status ${error.statusCode}`);
  }
  throw error;
}
```

`chatId` is the recipient's WhatsApp chat ID. The `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.whatsappLink` 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 Node SDK](https://docs.hypersender.com/v2/packages-and-sdks/node/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.