Create a playback token
curl --request POST \
--url https://test-api.segmnt.cloud/v1/projects/{projectId}/videos/{videoId}/playback-tokens \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"domain": "courses.example.com",
"expiresInSeconds": 14400
}
'import requests
url = "https://test-api.segmnt.cloud/v1/projects/{projectId}/videos/{videoId}/playback-tokens"
payload = {
"domain": "courses.example.com",
"expiresInSeconds": 14400
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({domain: 'courses.example.com', expiresInSeconds: 14400})
};
fetch('https://test-api.segmnt.cloud/v1/projects/{projectId}/videos/{videoId}/playback-tokens', 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://test-api.segmnt.cloud/v1/projects/{projectId}/videos/{videoId}/playback-tokens",
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([
'domain' => 'courses.example.com',
'expiresInSeconds' => 14400
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$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://test-api.segmnt.cloud/v1/projects/{projectId}/videos/{videoId}/playback-tokens"
payload := strings.NewReader("{\n \"domain\": \"courses.example.com\",\n \"expiresInSeconds\": 14400\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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://test-api.segmnt.cloud/v1/projects/{projectId}/videos/{videoId}/playback-tokens")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"domain\": \"courses.example.com\",\n \"expiresInSeconds\": 14400\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://test-api.segmnt.cloud/v1/projects/{projectId}/videos/{videoId}/playback-tokens")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"domain\": \"courses.example.com\",\n \"expiresInSeconds\": 14400\n}"
response = http.request(request)
puts response.read_body{
"token": "<string>",
"expiresAt": "2023-11-07T05:31:56Z",
"embedUrl": "<string>",
"thumbnailUrl": "<string>",
"playlistUrl": "https://test-cdn.segmnt.cloud/v/vid_9xR4tL/master.m3u8?token=..."
}{
"type": "<string>",
"title": "<string>",
"status": 123,
"code": "plan_limit_reached",
"detail": "<string>"
}{
"type": "<string>",
"title": "<string>",
"status": 123,
"code": "plan_limit_reached",
"detail": "<string>"
}{
"type": "<string>",
"title": "<string>",
"status": 123,
"code": "plan_limit_reached",
"detail": "<string>"
}{
"type": "<string>",
"title": "<string>",
"status": 123,
"code": "plan_limit_reached",
"detail": "<string>"
}{
"type": "<string>",
"title": "<string>",
"status": 123,
"code": "plan_limit_reached",
"detail": "<string>"
}{
"type": "<string>",
"title": "<string>",
"status": 123,
"code": "plan_limit_reached",
"detail": "<string>"
}Playback
Create a playback token
Call this from your server each time you show the video to a viewer.
The token is signed (HMAC) and holds the video ID, the expiry and the
allowed domain. The CDN refuses requests whose Origin or Referer is
another domain.
POST
/
v1
/
projects
/
{projectId}
/
videos
/
{videoId}
/
playback-tokens
Create a playback token
curl --request POST \
--url https://test-api.segmnt.cloud/v1/projects/{projectId}/videos/{videoId}/playback-tokens \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"domain": "courses.example.com",
"expiresInSeconds": 14400
}
'import requests
url = "https://test-api.segmnt.cloud/v1/projects/{projectId}/videos/{videoId}/playback-tokens"
payload = {
"domain": "courses.example.com",
"expiresInSeconds": 14400
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({domain: 'courses.example.com', expiresInSeconds: 14400})
};
fetch('https://test-api.segmnt.cloud/v1/projects/{projectId}/videos/{videoId}/playback-tokens', 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://test-api.segmnt.cloud/v1/projects/{projectId}/videos/{videoId}/playback-tokens",
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([
'domain' => 'courses.example.com',
'expiresInSeconds' => 14400
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$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://test-api.segmnt.cloud/v1/projects/{projectId}/videos/{videoId}/playback-tokens"
payload := strings.NewReader("{\n \"domain\": \"courses.example.com\",\n \"expiresInSeconds\": 14400\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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://test-api.segmnt.cloud/v1/projects/{projectId}/videos/{videoId}/playback-tokens")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"domain\": \"courses.example.com\",\n \"expiresInSeconds\": 14400\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://test-api.segmnt.cloud/v1/projects/{projectId}/videos/{videoId}/playback-tokens")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"domain\": \"courses.example.com\",\n \"expiresInSeconds\": 14400\n}"
response = http.request(request)
puts response.read_body{
"token": "<string>",
"expiresAt": "2023-11-07T05:31:56Z",
"embedUrl": "<string>",
"thumbnailUrl": "<string>",
"playlistUrl": "https://test-cdn.segmnt.cloud/v/vid_9xR4tL/master.m3u8?token=..."
}{
"type": "<string>",
"title": "<string>",
"status": 123,
"code": "plan_limit_reached",
"detail": "<string>"
}{
"type": "<string>",
"title": "<string>",
"status": 123,
"code": "plan_limit_reached",
"detail": "<string>"
}{
"type": "<string>",
"title": "<string>",
"status": 123,
"code": "plan_limit_reached",
"detail": "<string>"
}{
"type": "<string>",
"title": "<string>",
"status": 123,
"code": "plan_limit_reached",
"detail": "<string>"
}{
"type": "<string>",
"title": "<string>",
"status": 123,
"code": "plan_limit_reached",
"detail": "<string>"
}{
"type": "<string>",
"title": "<string>",
"status": 123,
"code": "plan_limit_reached",
"detail": "<string>"
}Authorizations
apiKeysession
Project API key. Server-side only.
Path Parameters
Pattern:
^prj_[A-Za-z0-9]+$Pattern:
^vid_[A-Za-z0-9]+$Body
application/json
Response
Token created.
Opaque. Do not parse it; the format can change.
Our player (hls.js) for an iframe on the token's domain. Shows our logo unless the plan has whiteLabel.
HLS master playlist for your own player (hls.js or Safari). Only on
plans with whiteLabel; other plans must use embedUrl, which shows
our logo. The CDN adds the token to every link inside the playlists.
Example:
"https://test-cdn.segmnt.cloud/v/vid_9xR4tL/master.m3u8?token=..."