Skip to content

Send OTP

Still using API v1?

This page documents the flow based Verify API V2. View V1 docs

Generate the One Time Password or Verification Token and send to the recipient.

Endpoint

POST
/verify/v2/otp/send-otp


POSTMAN

Authentication

AUTHORIZATION: Bearer Token

Body

Object

    {
      "recipient": "{{recipient}}",
      "flow_id": "login_otp"
    }

Body Parameters

Parameter Type Value Default
recipient String The phone number of the recipient. The recipient's phone number should have a country code prefix. -
flow_id String The id of the verification flow created in the user dashboard. The flow decides the channel, content, OTP type, code length, expiry and retry settings for the OTP. See the user guide for how to create a flow from the dashboard. -
success_url String The callback url to which the result is sent when the OTP is verified successfully (APPROVED). See Callback. -
failure_url String The callback url to which the result is sent when the verification fails (FAILED) or the OTP has expired (EXPIRED). See Callback. -

Response

When the request is validated, request_id, status and created time will be returned. Users can use this request_id to query status using the Get status endpoint.

200 - Success
{
    "request_id": "d9835609-a4e0-10ea-a26a-eeafbe700fef",
    "status": "accepted",
    "created_at": "2001-08-05T12:52:38.393Z"
}
401 - Unauthorized
{ 
    "detail": { 
    "code": "ACCESS_TOKEN_SIGNATURE_VERIFICATION_FAILED",
    "message": "It looks like your requests were failed due to a missing or invalid 'Access Token'. Sign up at https://app.d7networks.com and create an authentication token in the developer section."
    } 
} 
402 - Payment Required
    {
    "detail": [
        {
            "code": "INSUFFICIENT_CREDIT",
            "message": "It looks like your requests failed due to insufficient credit on our account. Sign in at https://app.d7networks.com and make a payment to resume the messaging service on your account or contact [email protected] to get more test credits."
        }
    ]
}
400 - Country Not Supported
{
    "detail": {
    "code": "COUNTRY_NOT_SUPPORTED",
    "message": "Verify service is not available for the destination country. Please contact support."
    }
}
422 - Validation Error
{
    "detail": [
        {
            "loc": [
            "string"
            ],
        "msg": "string",
        "type": "string"
        }
    ]
} 

Response Parameters

Parameter Type Value
otp_id String Unique id for each OTP generated. This otp_id is required to resend and verify OTP.
status String The status of OTP request. Possible request status are OPEN and FAILED.
expiry Integer Time in seconds from now until the expiry of OTP.

Callback

If success_url or failure_url is passed in the request, D7 sends the verification result to that url once the Verify OTP request is processed. If they are not passed, the callback urls saved on your account are used.

Verify OTP result Callback sent to otp_status
Correct OTP code success_url APPROVED
Wrong OTP code failure_url FAILED
OTP expired failure_url EXPIRED

The callback is sent as a POST request with Content-Type: application/json.

Callback Attributes

Parameter Value / Pattern Example(s)
otp_id The otp_id returned from the Send OTP endpoint d9835609-a4e0-10ea-a26a-eeafbe700fef
otp_status Verification result. Possible values are APPROVED, FAILED and EXPIRED APPROVED

Sample Callback

APPROVED - sent to success_url
{
    "otp_id": "d9835609-a4e0-10ea-a26a-eeafbe700fef",
    "otp_status": "APPROVED"
}
FAILED - sent to failure_url
{
    "otp_id": "d9835609-a4e0-10ea-a26a-eeafbe700fef",
    "otp_status": "FAILED"
}
EXPIRED - sent to failure_url
{
    "otp_id": "d9835609-a4e0-10ea-a26a-eeafbe700fef",
    "otp_status": "EXPIRED"
}

Note

Your callback url should respond with HTTP status 200. Any other response is retried up to 5 times with an increasing delay. The request times out after 10 seconds.

Programming Examples

1
2
3
4
5
6
7
curl --location --request POST 'https://api.d7networks.com/verify/v2/otp/send-otp' \
--header 'Authorization: Bearer {{api_access_token}}' \
--header 'Content-Type: application/json' \
--data-raw '{
    "recipient": "{{recipient1}}",
    "flow_id": "login_otp"
}'
npm i direct7
const Client = require('direct7')

const client = new Client(apiToken="Your API token")

const response = await client.verify.v2.sendOTP({
            recipient: "+9199999XXXXX",
            flow_id: "login_otp"
        })

console.log(response);
pip install direct7
1
2
3
4
5
6
7
from direct7 import Client

client = Client(api_token="Your API token")

client.verify.v2.send_otp(
    recipient="+97150900XXXX", 
    flow_id="login_otp")

composer require direct7/direct7-php
require_once 'vendor/autoload.php';
require_once __DIR__ . '/vendor/autoload.php';

use direct7\Direct7\Client;

$client = new Client(api_token="Your API token")

$response = $direct7->verify->v2->sendOtp(
    recipient:'+91999999XXXX', 
    flowId:'login_otp');

var_dump($response);
go get -u github.com/d7networks/direct7-go-sdk
1
2
3
4
5
6
7
8
9
import (
"github.com/d7networks/direct7-go-sdk/direct7"
    )   
apiToken := "Your Api Token"
client := direct7.NewClient(apiToken)
verify := direct7.NewVerify(client)
recipient := "{{recipient}}"
flowID := "login_otp"
response, err := verify.V2.SendOTP(recipient, flowID)
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\n    \"recipient\": \"{{recipient1}}\",\n    \"flow_id\": \"login_otp\"\n}");
Request request = new Request.Builder()
.url("https://api.d7networks.com/verify/v2/otp/send-otp")
.method("POST", body)
.addHeader("Authorization", "Bearer {{api_access_token}}")
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();
var headers = {
'Authorization': 'Bearer {{api_access_token}}',
'Content-Type': 'application/json'
};
var request = http.Request('POST', Uri.parse('https://api.d7networks.com/verify/v2/otp/send-otp'));
request.body = json.encode({
"recipient": "{{recipient1}}",
"flow_id": "login_otp"
});
request.headers.addAll(headers);

http.StreamedResponse response = await request.send();

if (response.statusCode == 200) {
print(await response.stream.bytesToString());
}
else {
print(response.reasonPhrase);
}
1
2
3
4
5
6
7
8
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", "Bearer {{api_access_token}}")
$headers.Add("Content-Type", "application/json")

$body = "{`n    `"recipient`": `"{{recipient1}}`",`n    `"flow_id`": `"login_otp`"`n}"

$response = Invoke-RestMethod 'https://api.d7networks.com/verify/v2/otp/send-otp' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json
gem install direct7
1
2
3
4
5
6
7
require 'direct7'

client = Direct7::Client.new('Your API token')

client.verify.v2.send_otp(
    recipient="+97150900XXXX", 
    flow_id="login_otp")
1
2
3
4
5
6
7
8
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://api.d7networks.com/verify/v2/otp/send-otp");
request.Headers.Add("Authorization", "Bearer {{api_access_token}}");
var content = new StringContent("{\n    \"recipient\": \"{{recipient1}}\",\n    \"flow_id\": \"login_otp\"\n}", null, "application/json");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());