Skip to content

Send OTP

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

Endpoint

POST
/verify/v1/otp/send-otp


POSTMAN

Authentication

AUTHORIZATION: Bearer Token

Body

Object

    {
      "originator": "SignOTP",
      "recipient": "{{recipient}}",
      "content": "Greetings from D7 API, your mobile verification code is: {}",
    }

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. -
originator string Brand name or number that shows up on the receiving phone, indicating who sent the text message. D7VERIFY
content String OTP Message Content with {} as placeholder for the OTP. -
template_id Integer You can create a template in the user dashboard for the OTP message content and use the id of that registered template instead of content parameter -
channel String The channel through which OTP will be sent. (Options: SMS, WhatsApp. Default: SMS) SMS
expiry Integer The maximum time in seconds, during which the OTP will be active and afterwards no verification can be done with that OTP . 600
data_coding String Set as text for normal GSM 03.38 characters(English, normal characters). Set as unicode for non GSM 03.38 characters (Arabic, Chinese, Hebrew, Greek like regional languages and Unicode characters). Set as auto so we will find the data_coding based on your content. text
retry_delay Integer The minimum time delay between frequent OTP resend requests in seconds. 60
retry_count Integer The number of times, the end user can request for OTP resend. 5
otp_code_length Integer The number of characters/digits in the OTP 6
otp_type String Direct7 supports three types of OTPs: alpha, numeric and alphanumeric numeric
success_url String The postback url to which, the successful OTP delivery response to be sent. -
failure_url String The postback url to which, the failed OTP delivery response to be sent. -

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."
        }
    ]
}
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.

Programming Examples

1. Without using OTP message templates

curl --location --request POST 'https://api.d7networks.com/verify/v1/otp/send-otp' \
--header 'Authorization: Bearer {{api_access_token}}' \
--header 'Content-Type: application/json' \
--data-raw '{
    "originator": "SignOTP",
    "recipient": "{{recipient1}}",
    "content": "Greetings from D7 API, your mobile verification code is: {}",
    "expiry": "600",
    "data_coding": "text"
}'
npm i direct7
const Client = require('direct7')

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

const response = await client.verify.sendOTP({
            originator: "SignOTP", recipient: "+9199999XXXXX",
            content: "Greetings from D7 API, your mobile  verification code is: {}",
            expiry: 600,
            data_coding: "text"
        })

console.log(response);
pip install direct7
from direct7 import Client

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

client.verify.send_otp(
    originator="SignOTP", 
    recipient="+97150900XXXX", 
    content = "Greetings from D7 API, your mobile verification code is: {}", 
    expiry = 600, 
    data_coding = "text")

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->sendOtp(
    originator:'SignOTP', 
    recipient:'+91999999XXXX', 
    content:'Greetings from D7 API, your mobile verification code is: {}', 
    data_coding:'text', 
    expiry:600);

var_dump($response);
go get -u github.com/d7networks/direct7-go-sdk
import (
"github.com/d7networks/direct7-go-sdk/direct7"
    )   
apiToken := "Your Api Token"
client := direct7.NewClient(apiToken)
verify := direct7.NewVerify(client)
originator := "SignOTP"
recipient := "{{recipient}}"
content := "Greetings from D7 API, your mobile verification code is: {}"
dataCoding := "text"
expiry := 600
response, err := verify.SendOTP(originator, recipient, content, dataCoding, expiry)
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\n    \"originator\": \"SignOTP\",\n    \"recipient\": \"{{recipient1}}\",\n    \"content\": \"Greetings from D7 API, your mobile verification code is: {}\",\n    \"expiry\": \"600\",\n    \"data_coding\": \"text\"\n}");
Request request = new Request.Builder()
.url("https://api.d7networks.com/verify/v1/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/v1/otp/send-otp'));
request.body = json.encode({
"originator": "SignOTP",
"recipient": "{{recipient1}}",
"content": "Greetings from D7 API, your mobile verification code is: {}",
"expiry": "600",
"data_coding": "text"
});
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    `"originator`": `"SignOTP`",`n    `"recipient`": `"{{recipient1}}`",`n    `"content`": `"Greetings from D7 API, your mobile verification code is: {}`",`n    `"expiry`": `"600`",`n    `"data_coding`": `"text`"`n}"

$response = Invoke-RestMethod 'https://api.d7networks.com/verify/v1/otp/send-otp' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json
gem install direct7
require 'direct7'

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

client.verify.send_otp(
    originator="SignOTP", 
    recipient="+97150900XXXX", 
    content = "Greetings from D7 API, your mobile verification code is: {}", 
    expiry = 600, 
    data_coding = "text")
1
2
3
4
5
6
7
8
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://api.d7networks.com/verify/v1/otp/send-otp");
request.Headers.Add("Authorization", "Bearer {{api_access_token}}");
var content = new StringContent("{\n    \"originator\": \"SignOTP\",\n    \"recipient\": \"{{recipient1}}\",\n    \"content\": \"Greetings from D7 API, your mobile verification code is: {}\",\n    \"data_coding\": \"auto\" \n}", null, "application/json");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());

2. Using OTP message templates

1
2
3
4
5
6
7
8
curl --location 'https://api.d7networks.com/verify/v1/otp/send-otp' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {{api_access_token}}' \
--data '{
    "originator": "SignOTP",
    "recipient": "{{recipient1}}",
    "template_id": "25" 
}'
npm i direct7
const Client = require('direct7')

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

const response = await client.verify.sendOTP({
            originator: "SignOTP", 
            recipient: "+9199999XXXXX",
            template_id: 25
        })

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

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

client.verify.send_otp(
    originator="SignOTP", 
    recipient="+97150900XXXX", 
    template_id= 25)

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->sendOtp(
    originator:'SignOTP', 
    recipient:'+91999999XXXX', 
    template_id: 25);

var_dump($response);
go get -u github.com/d7networks/direct7-go-sdk
import (
"github.com/d7networks/direct7-go-sdk/direct7"
    )   
apiToken := "Your Api Token"
client := direct7.NewClient(apiToken)
verify := direct7.NewVerify(client)
originator := "SignOTP"
recipient := "{{recipient}}"
templateID := 25
response, err := verify.SendOTP(originator, recipient, templateID)
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\n    \"originator\": \"SignOTP\",\n    \"recipient\": \"{{recipient1}}\",\n    \"template_id\": \"25\" \n}");
Request request = new Request.Builder()
.url("https://api.d7networks.com/verify/v1/otp/send-otp")
.method("POST", body)
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", "Bearer {{api_access_token}}")
.build();
Response response = client.newCall(request).execute();
var headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer {{api_access_token}}'
};
var request = http.Request('POST', Uri.parse('https://api.d7networks.com/verify/v1/otp/send-otp'));
request.body = json.encode({
"originator": "SignOTP",
"recipient": "{{recipient1}}",
"template_id": "25"
});
request.headers.addAll(headers);

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

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

$body = @"
{
    `"originator`": `"SignOTP`",
    `"recipient`": `"{{recipient1}}`",
    `"template_id`": `"25`" 
}
"@

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

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

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