Obtaining OTP using API
OTP are tokens generated using VdoCipher API which are required to authorize video playback. The OTP must always be generated on a back-end server. The generated OTP must then be sent to the website front-end. In the website front-end the OTP is used as part of the video embed code.
To generate the OTP you need to send an HTTP POST request to the API Endpoint, with the required OTP request Header and the optional OTP request Body. This article is specific to API Version v3.
API endpoint to retrieve OTP is https://dev.vdocipher.com/api/videos/{videoID}/otp
The authorization header containing the client secret key is to be appended to the OTP request. Refer to the OTP request body page for advance options that you can set as part of OTP request.
For valid requests the API server returns a JSON containing the otp
and playbackInfo
:
{
"otp":"1234567890abcdefghijk",
"playbackInfo": "z1y2x3w4v5u6t7s8r9q10"
}
You would need to send both otp
and playbackInfo
to your website front-end as part of the embed code.
Get OTP Sample Codeβ
The sample videoID is 1234567890
and the API Secret Key is a1b2c3d4e5
. The time-to-live for OTP validity is set to 300s in the sample code. See the OTP Advanced Options section for details.
- CURL
- NODE
- PHP
- C#
- Python
- Ruby
curl -X POST \
https://dev.vdocipher.com/api/videos/1234567890/otp \
-H 'Accept: application/json' \
-H 'Authorization: Apisecret a1b2c3d4e5' \
-H 'Content-Type: application/json' \
-d '{
"ttl":300
}'
var request = require('request');
var options = {
method: 'POST',
url: 'https://dev.vdocipher.com/api/videos/1234567890/otp',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': 'Apisecret a1b2c3d4e5',
},
body: {ttl: 300},
json: true,
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://dev.vdocipher.com/api/videos/1234567890/otp",
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([
"ttl" => 300,
]),
CURLOPT_HTTPHEADER => array(
"Accept: application/json",
"Authorization: Apisecret a1b2c3d4e5",
"Content-Type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
var client = new RestClient("https://dev.vdocipher.com/api/videos/1234567890/otp");
var request = new RestRequest(Method.POST);
request.AddHeader("Accept", "application/json");
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Authorization", "Apisecret a1b2c3d4e5");
request.AddParameter("undefined", "{\n\t\"ttl\":300\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
import requests
import json
url = "https://dev.vdocipher.com/api/videos/1234567890/otp"
payloadStr = json.dumps({'ttl': 300})
headers = {
'Authorization': "Apisecret a1b2c3d4e5",
'Content-Type': "application/json",
'Accept': "application/json"
}
response = requests.request("POST", url, data=payloadStr, headers=headers)
print(response.text)
require 'uri'
require 'json'
require 'net/http'
url = URI("https://dev.vdocipher.com/api/videos/1234567890/otp")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Apisecret a1b2c3d4e5'
request["Content-Type"] = 'application/json'
request["Accept"] = 'application/json'
request.body = ({:ttl => 300}).to_json
response = http.request(request)
puts response.read_body