Skip to main content

Sending OTPs

One of the primary use cases when using textly is verification & authentication, we provide an easy to use endpoint for dispatching OTPs to your user's phone numbers.

const myApiToken = await getApiToken(); // See authentication guide to learn how to get a token

const response = await fetch("https://api.textly.ly/api/v1/client/send_otp", {
method: "POST",
headers: new Headers({
"Content-Type": "application/json",
Authorization: `Bearer ${myApiToken}`,
}),
body: JSON.stringify({
target_number: "09100000",
wait_for_send: true,
}),
});

As we can see from the code snippet the /api/v1/client/send_otp expects a json body that contains

{
"target_number": "09100000",
"wait_for_send": true
}
  • target_number: is the number the OTP is going to be sent to
  • wait_for_send: whether or not to immediately send the message or have it be scheduled to send 3 to 5 seconds (optional)