Videos

Create Expirable Links

Create expirable playback links that open DynTube-hosted videos in the browser.

An expirable link opens the DynTube video player in the browser. If you need playback URLs for your own player, use Token Authentication.

POST https://api.dyntube.com/v1/videos/{id}/expirable-link

Headers

Name / Type / Description
NameTypeDescription
AuthorizationStringBearer YOUR_API_KEY

Request Body

Name / Type / Description
NameTypeDescription
limitPlaysBooleantrue or false
totalPlaysIntegerTotal number of plays (only used if limitPlays is true).
activationDateDateTimeRequired. ISO 8601 (UTC).
expiryDateDateTimeRequired. ISO 8601 (UTC).

200: OK

text
https://videos.dyntube.com/videos/exp-AYeYlXQEa71N0A

To embed an expirable link in your own web app, replace videos with iframe in the generated URL.

The link: https://videos.dyntube.com/videos/exp-AYeYlXQEa71N0A

Becomes: https://videos.dyntube.com/iframe/exp-AYeYlXQEa71N0A

C# Sample

csharp
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text.Json;
using System.Threading.Tasks;

public class DynTubeApiClient
{
    private readonly string _baseUrl;
    private readonly string _bearerToken;

    public DynTubeApiClient(string baseUrl, string bearerToken)
    {
        _baseUrl = baseUrl;
        _bearerToken = bearerToken;
    }

    public async Task CreateExpirableLink(string id, int limitPlays, int totalPlays, DateTime activationDate, DateTime expiryDate)
    {
        using (var client = new HttpClient())
        {
            client.DefaultRequestHeaders.Authorization =
                new AuthenticationHeaderValue("Bearer", _bearerToken);

            // Construct the request data
            var requestData = new {
                limitPlays = limitPlays,
                totalPlays = totalPlays,
                activationDate = activationDate,
                expiryDate = expiryDate
            };

            var requestDataJson = JsonSerializer.Serialize(requestData);

            var request = new HttpRequestMessage(HttpMethod.Post, $"{_baseUrl}/videos/{id}/expirable-link");
            request.Content = new StringContent(requestDataJson, System.Text.Encoding.UTF8, "application/json");

            var response = await client.SendAsync(request);

            if (response.IsSuccessStatusCode)
            {
                var link = await response.Content.ReadAsStringAsync();
                Console.WriteLine($"Expirable link created: {link}");
            }
            else
            {
                Console.WriteLine($"Error creating expirable link. Status code: {response.StatusCode}");
            }
        }
    }
}

public class Program
{
    public static async Task Main()
    {
        var client = new DynTubeApiClient("https://api.dyntube.com/v1", "YOUR_API_KEY");
        await client.CreateExpirableLink(
            "VIDEO_ID",
            1,
            5,
            DateTime.UtcNow,
            DateTime.UtcNow.AddDays(1));
    }
}

Python

python
import requests
import datetime

def create_expirable_link(id, bearer_token, limit_plays, total_plays, activation_date, expiry_date):
    headers = {
        "Authorization": f"Bearer {bearer_token}",
        "Content-Type": "application/json"
    }

    data = {
        "limitPlays": limit_plays,
        "totalPlays": total_plays,
        "activationDate": activation_date,
        "expiryDate": expiry_date
    }

    response = requests.post(f"https://api.dyntube.com/v1/videos/{id}/expirable-link", headers=headers, json=data)

    if response.status_code == 200:
        link = response.text
        print(f"Expirable link created: {link}")
    else:
        print(f"Error creating expirable link. Status code: {response.status_code}")

# Example call:
# create_expirable_link("video_id", "token", True, 5, datetime.datetime.utcnow().isoformat() + "Z", (datetime.datetime.utcnow() + datetime.timedelta(days=1)).isoformat() + "Z")

Node.js

javascript
const axios = require('axios');

async function create_expirable_link(id, bearer_token, limitPlays, totalPlays, activationDate, expiryDate) {
    try {
        const response = await axios.post(`https://api.dyntube.com/v1/videos/${id}/expirable-link`, {
            limitPlays: limitPlays,
            totalPlays: totalPlays,
            activationDate: activationDate,
            expiryDate: expiryDate
        }, {
            headers: {
                Authorization: `Bearer ${bearer_token}`
            }
        });

        const link = response.data;
        console.log(`Expirable link created: ${link}`);
    } catch (error) {
        console.error(error);
    }
}

// Example:
// create_expirable_link('video_id', 'your_token', true, 5, new Date().toISOString(), new Date(Date.now() + 86400000).toISOString());

PHP

php
function create_expirable_link($id, $bearer_token, $limit_plays, $total_plays, $activation_date, $expiry_date) {
  $headers = [
    "Authorization: Bearer $bearer_token",
    "Content-Type: application/json"
  ];

  $data = [
    "limitPlays" => $limit_plays,
    "totalPlays" => $total_plays,
    "activationDate" => $activation_date,
    "expiryDate" => $expiry_date
  ];

  $ch = curl_init("https://api.dyntube.com/v1/videos/$id/expirable-link");
  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  $response = curl_exec($ch);
  $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  curl_close($ch);

  if ($http_status == 200) {
    echo "Expirable link created: $response\n";
  } else {
    echo "Error creating expirable link. Status code: $http_status\n";
  }
}

[^1]:

  • Token Authentication when you need signed URLs for your own video player.
  • Get video to retrieve the video ID and playback fields.
  • Get video for mobile app/custom player for direct HLS or MP4 playback guidance.

Something missing or wrong here? Tell us and we will correct it. New to DynTube? Start with uploading and embedding.