Generate OTP
curl --request POST \
--url https://api.cashfree.com/ppi/otp/generate \
--header 'Content-Type: application/json' \
--header 'x-api-version: <x-api-version>' \
--header 'x-client-id: <api-key>' \
--header 'x-client-secret: <api-key>' \
--data '
{
"otp_verification_id": "Test123",
"user_id": "USER827364",
"notification_modes": [
"SMS",
"WHATSAPP"
]
}
'import requests
url = "https://api.cashfree.com/ppi/otp/generate"
payload = {
"otp_verification_id": "Test123",
"user_id": "USER827364",
"notification_modes": ["SMS", "WHATSAPP"]
}
headers = {
"x-api-version": "<x-api-version>",
"x-client-id": "<api-key>",
"x-client-secret": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'x-api-version': '<x-api-version>',
'x-client-id': '<api-key>',
'x-client-secret': '<api-key>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
otp_verification_id: 'Test123',
user_id: 'USER827364',
notification_modes: ['SMS', 'WHATSAPP']
})
};
fetch('https://api.cashfree.com/ppi/otp/generate', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.cashfree.com/ppi/otp/generate",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'otp_verification_id' => 'Test123',
'user_id' => 'USER827364',
'notification_modes' => [
'SMS',
'WHATSAPP'
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-api-version: <x-api-version>",
"x-client-id: <api-key>",
"x-client-secret: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.cashfree.com/ppi/otp/generate"
payload := strings.NewReader("{\n \"otp_verification_id\": \"Test123\",\n \"user_id\": \"USER827364\",\n \"notification_modes\": [\n \"SMS\",\n \"WHATSAPP\"\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-api-version", "<x-api-version>")
req.Header.Add("x-client-id", "<api-key>")
req.Header.Add("x-client-secret", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.cashfree.com/ppi/otp/generate")
.header("x-api-version", "<x-api-version>")
.header("x-client-id", "<api-key>")
.header("x-client-secret", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"otp_verification_id\": \"Test123\",\n \"user_id\": \"USER827364\",\n \"notification_modes\": [\n \"SMS\",\n \"WHATSAPP\"\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.cashfree.com/ppi/otp/generate")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-api-version"] = '<x-api-version>'
request["x-client-id"] = '<api-key>'
request["x-client-secret"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"otp_verification_id\": \"Test123\",\n \"user_id\": \"USER827364\",\n \"notification_modes\": [\n \"SMS\",\n \"WHATSAPP\"\n ]\n}"
response = http.request(request)
puts response.read_body{
"otp_verification_id": "Test123",
"cf_otp_verification_id": "8901234567890123456",
"status": "OTP_GENERATED",
"user_id": "USER827364",
"notification_modes": [
"SMS",
"WHATSAPP"
]
}Generate OTP
Sends an OTP (One-Time Password) to the user via the specified notification modes. Supports multiple delivery channels including SMS and WhatsApp for secure user verification.
POST
/
ppi
/
otp
/
generate
Generate OTP
curl --request POST \
--url https://api.cashfree.com/ppi/otp/generate \
--header 'Content-Type: application/json' \
--header 'x-api-version: <x-api-version>' \
--header 'x-client-id: <api-key>' \
--header 'x-client-secret: <api-key>' \
--data '
{
"otp_verification_id": "Test123",
"user_id": "USER827364",
"notification_modes": [
"SMS",
"WHATSAPP"
]
}
'import requests
url = "https://api.cashfree.com/ppi/otp/generate"
payload = {
"otp_verification_id": "Test123",
"user_id": "USER827364",
"notification_modes": ["SMS", "WHATSAPP"]
}
headers = {
"x-api-version": "<x-api-version>",
"x-client-id": "<api-key>",
"x-client-secret": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'x-api-version': '<x-api-version>',
'x-client-id': '<api-key>',
'x-client-secret': '<api-key>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
otp_verification_id: 'Test123',
user_id: 'USER827364',
notification_modes: ['SMS', 'WHATSAPP']
})
};
fetch('https://api.cashfree.com/ppi/otp/generate', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.cashfree.com/ppi/otp/generate",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'otp_verification_id' => 'Test123',
'user_id' => 'USER827364',
'notification_modes' => [
'SMS',
'WHATSAPP'
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-api-version: <x-api-version>",
"x-client-id: <api-key>",
"x-client-secret: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.cashfree.com/ppi/otp/generate"
payload := strings.NewReader("{\n \"otp_verification_id\": \"Test123\",\n \"user_id\": \"USER827364\",\n \"notification_modes\": [\n \"SMS\",\n \"WHATSAPP\"\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-api-version", "<x-api-version>")
req.Header.Add("x-client-id", "<api-key>")
req.Header.Add("x-client-secret", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.cashfree.com/ppi/otp/generate")
.header("x-api-version", "<x-api-version>")
.header("x-client-id", "<api-key>")
.header("x-client-secret", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"otp_verification_id\": \"Test123\",\n \"user_id\": \"USER827364\",\n \"notification_modes\": [\n \"SMS\",\n \"WHATSAPP\"\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.cashfree.com/ppi/otp/generate")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-api-version"] = '<x-api-version>'
request["x-client-id"] = '<api-key>'
request["x-client-secret"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"otp_verification_id\": \"Test123\",\n \"user_id\": \"USER827364\",\n \"notification_modes\": [\n \"SMS\",\n \"WHATSAPP\"\n ]\n}"
response = http.request(request)
puts response.read_body{
"otp_verification_id": "Test123",
"cf_otp_verification_id": "8901234567890123456",
"status": "OTP_GENERATED",
"user_id": "USER827364",
"notification_modes": [
"SMS",
"WHATSAPP"
]
}Authorizations
Your unique client identifier issued by Cashfree. You can find this in your Merchant Dashboard.
The secret key associated with your client ID. Use this to authenticate your API requests. You can find this in your Merchant Dashboard.
Headers
Body
application/json
Request parameters to generate an OTP for the user.
Response
Success response for generating an OTP.
Was this page helpful?