Latest Legacy

Overview

The Plivo API uses HTTP verbs and standard HTTP status codes to make it easier for you to integrate communications into your code. To secure your requests to our servers, we serve our API over HTTPS.

If you’re looking for our client SDKs, you can find them at iOS SDK, Android SDK, and Browser SDK.

Note: The current version of the API is v1, and the server SDKs are versioned as latest and legacy.

API Endpoint

POST https://api.plivo.com/{version}/

API Request

Plivo exposes a list of REST APIs to perform various actions. You can use these APIs in combination with Verify applications.

POST https://api.plivo.com/v1/

Authentication

All requests to the Verify API are authenticated with BasicAuth using your Auth ID and Auth Token, which you can find on the Overview page of the Plivo console.

Content-Type

Plivo only accepts input of the type application/json.

All POST requests arguments must be passed as json with the Content-Type set as application/json.

All GET and DELETE request arguments must be passed in the query string.

Timeouts and Proxies

The server SDKs provide for specifying timeouts and proxy settings to be used while making API requests. In the code window, select the programming language of your choice and click on the latest version to see how to specify these settings.

Pagination

Plivo uses offset-based pagination to list resources.

For instance, if a search request has a result of 100 objects with limit = 10 and offset = 5, then objects with indices 51 through 60 are returned.

Parameters used for pagination

limit integer

A limit on the number phone numbers to be returned. limit can range between 1 and 20, and the default is 20.

offset integer

A pagination cursor to denote the number of objects by which the results should be offset.

API Response

All Plivo API endpoints return a response in JSON format. An api_id in each response uniquely identifies each request. The API returns one of these HTTP status codes depending on whether the API call is successful or not.

HTTP status codes we send

200

Request has been executed

201

Resource created

202

Resource changed

204

Resource deleted

400

A parameter is missing or is invalid

401

Authentication failed

404

Resource cannot be found

405

HTTP method is not allowed

429

You are sending too many requests

500

Server error

Session

Plivo’s Session API is a simple REST interface for sending and validating one-time passwords (OTP) for two-factor authentication (2FA) using SMS and voice channels.

API Endpoint

POST https://api.plivo.com/v1/Account/{auth_id}/Verify/

The Session object

The API creates a Session object once for each recipient within the code expiry time. You can configure your expiry time while creating applications.

A Session object has these attributes.

Attributes

session_uuid string

A 36-character string that uniquely identifies a session detail record.

app_uuid string

ID of the application used to trigger the session.

recipient string

The destination phone number (in E.164 format) to which the message was sent.

status string

The current status of the session.

Allowed values: in-progress, verified and expired.

channel string

The last channel used for the session.

locale string

This is the language translation in which your session was attempted.

This feature is available upon request only. Raise a support ticket and provide the translations you want to use.

otp_attempts object

An object containing details of all the attempts made during a session and the same channel, ID, time, and status.

chargesobject

An object containing details of all the charges incurred during a session and the same channel, ID, and charge.

created_atstring

UTC time when the session was created.

updated_atstring

UTC time when the session was last updated.

Create a session

This API lets you send OTPs via Plivo’s SMS or Voice services.

API Endpoint

POST https://api.plivo.com/v1/Account/{auth_id}/Verify/Session/

Arguments

app_uuid stringoptional

The UUID of the application you want to use for this session. Defaults to UUID of the default application for your account.

recipient stringrequired

The phone number to which the message is to be delivered.

channel stringoptional

The channel you want to use for sending the code.

Allowed values:sms,voice
Defaults tosms

method stringoptional

The HTTP method to be used when calling the URL defined above.

Allowed values:GET,POST
Defaults toPOST

Url stringoptional

Set this parameter to the fully qualified URL to which status update callbacks for the session should be sent. Read more about the session attributes passed to this callback URL.

locale stringoptional

Set this parameter to determine the language you want to use. Defaults to ‘en’.

The locale value is obtained by combining language code in ISO 639-1 format and region code in ISO 3166-1 format (optional). For example: en_US, en, en_GB, es, fr_FR etc.

This feature is available upon request only. Raise a support ticket and provide the translations you want to use.

brand_namestringoptional

This is the brand name that users will see in their Verify messages. It replaces the string “${brand_name}“ in the Verify template of your choice. It is relevant to the ‘Voice’ and 'SMS' channels.

Please note that passing a brand_name overrides the Brand Name configured in the Verify application.

app_hashstringoptional

Relevance: 'SMS' Channel and Android OS only

This is the text string that the SMS Retriever API will look for to match the received SMS OTP to your android application. Please refer to Google's documentation on how to compute your app's hash string. The “app_hash” will be appended at the end of your verification SMS body.

code_lengthintegeroptional

Valid Values: 4 to 8 (inclusive)
Set this parameter to override the default length of the code/OTP as defined in the configuration of the relevant Verify application.

Returns

Returns a JSON response containing the API request ID and session UUID.

Example Request

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import sys
sys.path.append("../plivo-python")
import plivo

client = plivo.RestClient('<auth_id>','<auth_token>')

response = client.verify_session.create(
            recipient='<destination number>',
            app_uuid='<verify application uuid>',
            channel='<sms/voice>',
            url='<callback url>',
            method='<callback method:post/get>'
            )

print(response)

Was this code helpful

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
require "rubygems"
require "/usr/src/app/lib/plivo.rb"
include Plivo
# Environment
api = RestClient.new("<auth_id>", "<auth_token>")
app_uuid='<app_uuid>'
channel='<channel>'
url='https://<yourdomain>.com/session_status/'
method='POST'
recipient='<recipient>'
begin
puts("Create Session")
response = client.verify_session.create(app_uuid,recipient,channel,url,method)
puts response
rescue PlivoRESTError => e
puts 'Exception: ' + e.message
end

Was this code helpful

1
2
3
let plivo = require('plivo') 
let client = new plivo.Client('<auth_id>','<auth_token>'); 
client.verify_session.create({ app_uuid:'<app_uuid>', recipient: '<recipient>', url:'https://<yourdomain>.com/sms_status/', method:'POST', channel:'sms' }).then(function(response) { console.log(response) });

Was this code helpful

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php
require '/usr/src/app/vendor/autoload.php';
use Plivo\RestClient;
use Plivo\Exceptions\PlivoResponseException;

// ENVIRONMENT
$client = new RestClient("<auth_id>", "<auth_token>");

$optionalArgs=array("url" => "https://<yourdomain>.com/sms_status/", "method" =>"POST", "channel"=>"sms","app_uuid"=>"<app_uuid>");


// Create Session
try {
$response1 = $client->verifySessions->create(
"<recipient>",$optionalArgs
);
print_r($response1);
}
catch (Exception $ex) {
print_r($ex);
}
?>

Was this code helpful

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import java.io.IOException;
import java.net.URL;
import java.util.Collections;
import com.plivo.api.Plivo;
import com.plivo.api.exceptions.PlivoRestException;
import com.plivo.api.models.verify_session.VerifySession;
import com.plivo.api.models.verify_session.SessionCreateResponse;
import com.plivo.api.models.message.Message;
import com.plivo.api.exceptions.PlivoValidationException;
import com.plivo.api.models.base.ListResponse;
class Session {
    public static void main(String[] args) {
        Plivo.init("<auth_id>", "<auth_token>");
        try {
          SessionCreateResponse response = VerifySession.creator(
                    "<app_uuid>", 
                    "<recipient>", "<channel>", "<callback_url>", "<method>") 
                    .create();
            System.out.println(response);
        }

        catch (PlivoRestException | IOException e) {
            e.printStackTrace();
        }
    }
}

Was this code helpful

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
using System;
using System.Collections.Generic;
using Plivo;
using Plivo.Exception;
namespace dotnet_sdk
{
    class Session
    {
        static void Main(string[] args)
        {
            // ENVIRONMENT
            var api = new PlivoApi("<auth_id>", "<auth_token>"); 
            // Create Session
             try {   
                 Console.WriteLine("Create Session");
                 var response = api.VerifySession.Create(recipient:"<recipient>",app_uuid:"<app_uuid>",url:"<callback_url>",method:"POST",channel:"<channel>");
                 Console.WriteLine(response);
             }
catch (PlivoRestException e){
                Console.WriteLine("Exception: " + e.Message);
            }
}
}
}

Was this code helpful

1
2
3
4
5
6
7
8
9
10
curl -i --user auth_id:auth_token \
    -H "Content-Type: application/json" \
    -d '{ 
     "app_uuid":"<app_uuid>",
    "recipient": "<recipient>",
    "url":"<callback_url>",
    "channel":"sms",
    "method":"POST"
}' \
   https://api.plivo.com/v1/Account/{auth_id}/Verify/Session/

Was this code helpful

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package main

import (
"fmt"
"encoding/json"

"github.com/plivo/plivo-go"
)

func main() {
client, err := plivo.NewClient("<auth_id>", "<auth_token>", &plivo.ClientOptions{})
if err != nil {
fmt.Printf("Error:\n", err)
}
//Create Session
response, err := client.VerifySession.Create(
plivo.SessionCreateParams{
Recipient: "<destinatination number>",
AppUUID: "<verify application uuid>",
Channel: "<sms/voice>",
URL: "<callback url>",
Method: "<callback method:post/get>",
},
)
if err != nil {
fmt.Print("Error", err.Error())
return
}
res, _ := json.Marshal(response)
fmt.Printf("Response: \n\n %#v \n", string(res))
}

Was this code helpful

Response

{
    "api_id": "3335cb16-d297-4e00-a5e6-66d2bb03b323",
    "message": "Session initiated",
    "session_uuid": "8e712097-8090-4644-81e7-8f4265d8354e"
}

Retrieve a session

Retrieves a session.

API Endpoint

GET https://api.plivo.com/v1/Account/{auth_id}/Verify/Session/{session_uuid}/

Arguments

No arguments need to be passed.

Returns

This API call returns the details for the session identified by the session_uuid specified in the request URL.

Example Request

1
2
3
4
5
6
7
8
9
import sys
sys.path.append("../plivo-python")
import plivo

client = plivo.RestClient()

response = client.verify_session.get('<session uuid>')

print(response)

Was this code helpful

1
2
3
4
5
6
7
8
9
10
11
12
require "rubygems"
require "/usr/src/app/lib/plivo.rb"
include Plivo
#Environment
api = RestClient.new("<auth_id>", "<auth_token>")
begin
     puts("Get Session")
     response = api.verify_session.get('<session_uuid>')      
     puts response
rescue PlivoRESTError => e
     puts 'Exception: ' + e.message
end

Was this code helpful

1
2
3
4
5
6
let plivo = require('plivo')
let client = new plivo.Client('<auth_id>', '<auth_token>');
client.verify_session.get('<session_uuid>').then(function(response) {
let formattedResponse = JSON.stringify(response, null, 2);
console.log(formattedResponse);
});

Was this code helpful

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
require '/usr/src/app/vendor/autoload.php';
use Plivo\RestClient;
use Plivo\Exceptions\PlivoResponseException;

// ENVIRONMENT
$client = new RestClient("<auth_id>", "<auth_token>");

// Get a particular session detail
try {
$response = $client->verifySessions->get('<session_uuid>');
print_r($response);
}
catch (Exception $ex) {
print_r($ex);
}
?>

Was this code helpful

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import java.io.IOException;
import java.net.URL;
import java.util.Collections;
import com.plivo.api.Plivo;
import com.plivo.api.exceptions.PlivoRestException;
import com.plivo.api.models.verify_session.VerifySession;
import com.plivo.api.models.verify_session.SessionCreateResponse;
import com.plivo.api.models.message.Message;
import com.plivo.api.exceptions.PlivoValidationException;
import com.plivo.api.models.base.ListResponse;
class Session {
    public static void main(String[] args) throws PlivoValidationException {
      Plivo.init("<auth_id>", "<auth_token>");
      // Get Session
      try {
        VerifySession response = VerifySession.getter("<session_uuid>").get();
        System.out.println(response);
      } catch (PlivoRestException | IOException e) {
        e.printStackTrace();
      }
    }
}

Was this code helpful

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
using System;
using System.Collections.Generic;
using Plivo;
using Plivo.Exception;
namespace dotnet_sdk
{
    class Session
    {
        static void Main(string[] args)
        {
            //ENVIRONMENT
            var api = new PlivoApi("<auth_id>", "<auth_token>"); 
            //Get Session
             try
             {   
                Console.WriteLine("Get Session Details");
                var response = api.VerifySession.Get("<session_uuid");
                Console.WriteLine(response);
             }
catch (PlivoRestException e)
            {
                Console.WriteLine("Exception: " + e.Message);
            }

}
}
}

Was this code helpful

1
2
curl -i --user auth_id:auth_token \
    https://api.plivo.com/v1/Account/{auth_id}/Verify/Session/{session_uuid}/

Was this code helpful

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package main

import (
"fmt"
"encoding/json"

"github.com/plivo/plivo-go"
)

func main() {
client, err := plivo.NewClient("<auth_id>", "<auth_token>", &plivo.ClientOptions{})
if err != nil {
fmt.Printf("Error:\n", err)
}
//Get the details of a session
response_get, err := client.VerifySession.Get(response.SessionUUID)
if err != nil {
fmt.Print("Error", err.Error())
return
}
res1, _ := json.Marshal(response_get)
fmt.Printf("Response: \n\n %#v \n", string(res1))
}

Was this code helpful

Response

{
    "api_id": "abf7fc2b-fac5-471c-9592-74ed6834b5e6",
    "session_uuid": "60ea68db-b123-46d9-9eb2-1201d516dbbd",
    "app_uuid": "ec66515e-86f6-4507-8620-31c039538d7a",
    "recipient": "919380013443",
    "channel": "voice",
    "status": "Expired",
    "count": 3,
    "attempt_details": [
        {
            "channel": "voice",
            "attempt_uuid": "90cc6cde-db80-4d14-9716-3aaa2b403377",
            "status": "answer",
            "time": "2023-06-01T08:52:39.363253Z"
        },
        {
            "channel": "sms",
            "attempt_uuid": "acbffc94-283b-42b3-8a96-65cbc18a9624",
            "status": "delivered",
            "time": "2023-06-01T08:52:59.484375Z"
        },
        {
            "channel": "voice",
            "attempt_uuid": "04a81620-c4ab-45d6-847d-cc3ae6fec121",
            "status": "early media",
            "time": "2023-06-01T08:53:25.577153Z"
        }
    ],
    "charges": {
        "total_charge": "0.113",
        "validation_charge": "0.0000",
        "attempt_charges": [
            {
                "attempt_uuid": "90cc6cde-db80-4d14-9716-3aaa2b403377",
                "channel": "voice",
                "charge": "0.03300"
            },
            {
                "attempt_uuid": "acbffc94-283b-42b3-8a96-65cbc18a9624",
                "channel": "sms",
                "charge": "0.08000"
            },
            {
                "attempt_uuid": "04a81620-c4ab-45d6-847d-cc3ae6fec121",
                "channel": "voice",
                "charge": "0.00000"
            }
        ]
    },
    "created_at": "2023-06-01T08:52:39.363253Z",
    "updated_at": "2023-06-01T08:53:25.577153Z"
}

List all sessions

This API retrieves a list of sessions based on a filter criteria over the last 90 days.

Note: The default rate limit for this API is 20 requests per minute. If the rate limit is exceeded, the API will throw the error “too many requests”.

API Endpoint

GET https://api.plivo.com/v1/Account/{auth_id}/Verify/Session/

Arguments

app_uuid string

Filters results based on sessions sent using a specific application.

status string

Filter results by the current status of a session. Allowed values: in-progress,verified,expired

recipient string

Filters results by the number to which codes/OTPs were sent using Plivo APIs. You can filter the details by using the exact number in E.164 format — for example, +12025553434.

subaccount string

Filters for sessions sent using a specific subaccount’s Auth Token.

limit string

Denotes the number of results per page. The maximum number of results that can be fetched is 20.

Defaults to 20.

offset string

Denotes the number of value items by which the results should be offset. Defaults to 0. Read more about offset-based pagination.

session_time string

Filters sessions based on the time the session was initiated.

Timestamps are expected to be in YYYY-MM-DD HH:MM[:ss[.uuuuuu]] format, and are considered to be in UTC time zone.

If you do not specify this attribute, the sessions for the last 24 hours will be retrieved by default.

The filter can be used in five forms:

session_time: Use this argument to filter for session by exact timestamp. The format expected is YYYY-MM-DD HH:MM:ss:uuuuuu. To get all sessions that were sent or received at 2021-03-21 11:47:30.982811, use session_time=2021-03-21 11:47:30.982811
session_time__gt: gt stands for greater than. Use this argument to filter for sessions initiated after a given time. To get all session that were initiated after 2021-03-21 11:47, use session_time__gt=2021-03-21 11:47
session_time__gte: gte stands for greater than or equal to. To get all sessions that were initiated after or exactly at 2021-03-21 11:47[:30], use session_time__gte=2021-03-21 11:47[:30]
session_time__lt: lt stands for less than. Use this argument to filter for sessions initiated before a given time. To get all sessions that were initiated before 2021-03-21 11:47, use session_time__lt=2021-03-21 11:47
session_time__lte: lte stands for less than or equal to. To get all sessions that were initiated before or exactly at 2012-03-21 11:47[:30], use session_time__lte=2012-03-21 11:47[:30]
brand_namestring

Filters and lists all the sessions based on the specific brands that were passed in the session creation API.

app_hashstring

Filters and lists all the sessions based on the app hashes that were passed in the session creation API.

Note: The subaccount filter is implicitly applied when a subaccount’s API credentials are used to fire this API. This argument should be used only when the parent account’s API credentials are used to fire this API.

Returns

This API returns a list of sessions matching the filters specified in the request.

The API response also contains a meta field with the fields:

  • limit: the size of the page returned in the response
  • offset: the offset for the page returned in the response
  • next: the URL that points to the next page of results
  • previous: the URL that points to the previous page of results

Example Request

1
2
3
4
5
6
7
8
9
10
11
import sys
sys.path.append("../plivo-python")
import plivo

client = plivo.RestClient()

response = client.verify_session.list(
limit=2,
        	offset=6)

print(response)

Was this code helpful

1
2
3
4
5
6
7
8
9
10
11
12
require "rubygems"
require "/usr/src/app/lib/plivo.rb"
include Plivo
#Environment
api = RestClient.new("<auth_id>", "<auth_token>")
begin
     puts("List all Sessions")
     response = api.verify_session.list(limit:1,offset:0)
     puts response
rescue PlivoRESTError => e
     puts 'Exception: ' + e.message
end  

Was this code helpful

1
2
3
4
5
6
let plivo = require('plivo')
let client = new plivo.Client('<auth_id>', '<auth_token>');
client.verify_session.list().then(function(response) {
let formattedResponse = JSON.stringify(response, null, 2);
console.log(formattedResponse)
});

Was this code helpful

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php
require '/usr/src/app/vendor/autoload.php';
use Plivo\RestClient;
use Plivo\Exceptions\PlivoResponseException;

// ENVIRONMENT
$client = new RestClient("<auth_id>", "<auth_token>");


// List all sessions
try {
$response = $client->verifySessions->list(['limit' => '5','offset' => 0]);
print_r($response);
}
catch (Exception $ex) {
print_r($ex);
}

?>

Was this code helpful

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.io.IOException;
import java.net.URL;
import java.util.Collections;
import com.plivo.api.Plivo;
import com.plivo.api.exceptions.PlivoRestException;
import com.plivo.api.models.verify_session.VerifySession;
import com.plivo.api.models.verify_session.VerifySessionList;
import com.plivo.api.models.verify_session.SessionCreateResponse;
import com.plivo.api.models.message.Message;
import com.plivo.api.exceptions.PlivoValidationException;
import com.plivo.api.models.base.ListResponse;
class Session {
  public static void main(String[] args) throws PlivoValidationException {
    Plivo.init("<auth_id>", "<auth_token>");
   try
    {
      ListResponse<VerifySessionList> response = VerifySession.lister()
        .limit(1)
        .offset(0)
        .list();
    System.out.println(response);
}
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }
}

Was this code helpful

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
using System;
using System.Collections.Generic;
using Plivo;
using Plivo.Exception;
namespace dotnet_sdk
{
    class Session
    {
        static void Main(string[] args)
        {
            // ENVIRONMENT
            var api = new PlivoApi("<auth_id>", "<auth_token>");             
            // List all Sessions
             try
             {   
                Console.WriteLine("List all Sessions");
                var response = api.VerifySession.List(limit:1,offset:0);
                Console.WriteLine(response);
             }
catch (PlivoRestException e)
            {
                Console.WriteLine("Exception: " + e.Message);
            }

}
}
}

Was this code helpful

1
2
curl -i --user auth_id_ID:auth_token \
    https://api.plivo.com/v1/Account/{auth_id}/Verify/Session/

Was this code helpful

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package main

import (
"fmt"
"encoding/json"

"github.com/plivo/plivo-go"
)

func main() {
client, err := plivo.NewClient("<auth_id>", "<auth_token>", &plivo.ClientOptions{})
if err != nil {
fmt.Printf("Error:\n", err)
}

//List details of all sessions for the account with filter params
response_list, err := client.VerifySession.List(
plivo.SessionListParams{
Limit: 1,
Offset:2,
},
)
if err != nil {
fmt.Print("Error", err.Error())
return
}
res2, _ := json.Marshal(response_list)
fmt.Printf("Response: \n\n %#v \n", string(res2))

}

Was this code helpful

Response

 {
   "api_id": "3a7a0d6d-1b85-4593-921c-373e673a5799",
   "meta": {
       "limit": 20,
       "offset": 0,
       "next": null,
       "previous": null
   },
   "sessions": [
      {
           "session_uuid": "51e965f3-65a5-4ca0-9542-57154118a991",
           "app_uuid": "59728519-d145-45d6-8d46-60c06f7e8bbb",
           "recipient": "918681951370",
           "channel": "sms",
           "status": "expired",
           "count": 1,
           "attempt_details": [
               {
                   "channel": "sms",
                   "attempt_uuid": "bd460457-6c2f-4177-a879-e6a83c35d5a9",
                   "status": "undelivered",
                   "time": "2023-06-01T10:40:05.804031Z"
               }
           ],
           "charges": {
               "total_charge": "0.08",
               "validation_charge": "0.0000",
               "attempt_charges": [
                   {
                       "attempt_uuid": "bd460457-6c2f-4177-a879-e6a83c35d5a9",
                       "channel": "sms",
                       "charge": "0.08000"
                   }
               ]
           },


           "created_at": "2023-06-01T10:40:05.804031Z",
           "updated_at": "2023-06-01T10:40:05.804031Z"
       },


            {
           "session_uuid": "60ea68db-b123-46d9-9eb2-1201d516dbbd",
           "app_uuid": "ec66515e-86f6-4507-8620-31c039538d7a",
           "recipient": "919380013443",
           "channel": "voice",
           "status": "expired",
           "count": 3,
           "attempt_details": [
               {
                   "channel": "voice",
                   "attempt_uuid": "90cc6cde-db80-4d14-9716-3aaa2b403377",
                   "status": "ANSWER",
                   "time": "2023-06-01T08:52:39.363253Z"
               },
               {
                   "channel": "sms",
                   "attempt_uuid": "acbffc94-283b-42b3-8a96-65cbc18a9624",
                   "status": "delivered",
                   "time": "2023-06-01T08:52:59.484375Z"
               },
               {
                   "channel": "voice",
                   "attempt_uuid": "04a81620-c4ab-45d6-847d-cc3ae6fec121",
                   "status": "EARLY MEDIA",
                   "time": "2023-06-01T08:53:25.577153Z"
               }
           ],
           "charges": {
               "total_charge": "0.113",
               "validation_charge": "0.0000",
               "attempt_charges": [
                   {
                       "attempt_uuid": "90cc6cde-db80-4d14-9716-3aaa2b403377",
                       "channel": "voice",
                       "charge": "0.03300"
                   },
                   {
                       "attempt_uuid": "acbffc94-283b-42b3-8a96-65cbc18a9624",
                       "channel": "sms",
                       "charge": "0.08000"
                   },
                   {
                       "attempt_uuid": "04a81620-c4ab-45d6-847d-cc3ae6fec121",
                       "channel": "voice",
                       "charge": "0.00000"
                   }
               ]
           },
           "created_at": "2023-06-01T08:52:39.363253Z",
           "updated_at": "2023-06-01T08:53:25.577153Z"
       } 
       ] 
}

Validate a session

This API validates a session.

API Endpoint

POST https://api.plivo.com/v1/Account/{auth_id}/Verify/Session/{session_uuid}/

Arguments

otp stringrequired

The OTP that you want to validate against a particular session.

Returns

Returns a JSON response containing the API request ID and session UUID.

Example Request

1
2
3
4
5
6
7
8
9
10
11
import sys
sys.path.append("../plivo-python")
import plivo

client = plivo.RestClient('<auth_id>','<auth_token>')

response = client.verify_session.validate(
        session_uuid = '<session uuid>',
        otp='<otp value>')

print(response)

Was this code helpful

1
2
3
4
5
6
7
8
9
10
11
12
require "rubygems"
require "/usr/src/app/lib/plivo.rb"
include Plivo
#Environment
api = RestClient.new("<auth_id>", "<auth_token>")
begin
     puts("Validate Session")
     response = api.verify_session.validate('<session_uuid>','<otp>')
     puts response
rescue PlivoRESTError => e
     puts 'Exception: ' + e.message
end

Was this code helpful

1
2
3
4
5
6
7
let plivo = require('plivo')
let client = new plivo.Client('<auth_id>', '<auth_token>');
client.verify_session.validate({id:'<session_uuid>',otp:'<otp>'}).then(function(response) {
console.log(response)
}).catch(function (error) {
console.log(error)
});

Was this code helpful

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
require '/usr/src/app/vendor/autoload.php';
use Plivo\RestClient;
use Plivo\Exceptions\PlivoResponseException;

// ENVIRONMENT
$client = new RestClient("<auth_id>", "<auth_token>");


//Validate Session
try {
$response1 = $client->verifySessions->validate(
'<session_uuid>',
'<otp>'
);
print_r($response1);
}
catch (Exception $ex) {
print_r($ex);
}
?>

Was this code helpful

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.io.IOException;
import java.net.URL;
import java.util.Collections;
import com.plivo.api.Plivo;
import com.plivo.api.exceptions.PlivoRestException;
import com.plivo.api.models.verify_session.VerifySession;
import com.plivo.api.models.verify_session.VerifySessionList;
import com.plivo.api.models.verify_session.SessionCreateResponse;
import com.plivo.api.models.message.Message;
import com.plivo.api.exceptions.PlivoValidationException;
import com.plivo.api.models.base.ListResponse;

class Session {
  public static void main(String[] args) throws PlivoValidationException {
    Plivo.init("<auth_id>", "<auth_token>");
   try
    {
      SessionCreateResponse response = VerifySession.validation(
          "<session_uuid>", "<otp>") // Validation
        .create();
    System.out.println(response);
}
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }
}

Was this code helpful

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
using System;
using System.Collections.Generic;
using Plivo;
using Plivo.Exception;
namespace dotnet_sdk
{
    class Session
    {
        static void Main(string[] args)
        {
            // ENVIRONMENT
            var api = new PlivoApi("<auth_id>", "<auth_token>");             
            // Validate Session
             try
             {   
                Console.WriteLine("Validate Session");
                var response = api.VerifySession.Validate(session_uuid:"<session_uuid>",otp:"<otp>");
                Console.WriteLine(response);
             }
catch (PlivoRestException e)
            {
                Console.WriteLine("Exception: " + e.Message);
            }

}
}
}

Was this code helpful

1
2
3
4
5
6
curl -i --user auth_id:auth_token \
    -H "Content-Type: application/json" \
    -d '{ 
    "OTP": "<otp>"
}' \
    https://api.plivo.com/v1/Account/{auth_id}/Verify/Session/{session_uuid}/

Was this code helpful

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package main

import (
        "fmt"
        "encoding/json"

        "github.com/plivo/plivo-go"
)

func main() {
client, err := plivo.NewClient("<auth_id>", "<auth_token>", &plivo.ClientOptions{})
if err != nil {
fmt.Printf("Error:\n", err)
}

        //Validate
        response_validate, err := client.VerifySession.Validate(
                plivo.SessionValidationParams{
                        OTP: "<otp value>",
                }, "<SessionUUID>",
        )
        if err != nil {
                fmt.Print("Error", err.Error())
                return
        }
        res3, _ := json.Marshal(response_validate)
        fmt.Printf("Response Validation: \n\n %#v \n", string(res3))
}

Was this code helpful

Response

{
    "api_id": "e7af31b5-a7cb-40d6-a3ab-122fdcc9f0fe",
    "message": "session validated successfully.",
}

Verify Status Callbacks

The best way to keep track of the status of your Verify sessions is to set up a server endpoint to receive status update events in real-time.

Once you’ve configured this endpoint, specify its URL and HTTP method in the create a verify session request. Plivo will call this endpoint with the latest Verify session details as and when the session status changes.

Attributes

With every status change event, these message attributes are passed to the status update URL. They’re passed as form data if the method configured is POST, and as query parameters if it’s GET.

AttemptSequence string

This indicates the sequence of the verification attempt for which you are receiving this callback.

AttemptUUID string

This is the unique identifier for the SMS that was sent or Voice call that was triggered as part of the Verify session.

Channel string

The channel you used to send the code.

Possible values: sms,voice

ChannelErrorCode string

This is the error code returned by the channel on which verification was attempted.

ChannelStatus string

This indicates the status of your verification request based on the specified channel. Possible values:

sms - queued, sent, undelivered, failed, delivered

voice - in-progress, completed, ringing

Recipient string

The phone number to which the message is to be delivered.

RequestTime string

UTC time when this attempt was created.

SessionStatus string

The current status of the session.

Possible values: in-progress and expired.

SessionUUID string

A 36-character string that uniquely identifies a session detail record.