Create Expirable Links

Our API allows you to create expirable links for the videos that can be opened in the browser to play the videos.

Please note that an expirable link will actually load our video player in the browser and allow it to play. If you need to create links that can be used within a video player, use our "Token Authentication

This

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

Request Body

https://play.dyntube.io/videos/exp-AYeYlXQEa71N0A

C# Sample

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())
        {
            // Add the bearer token to the request headers
            client.DefaultRequestHeaders.Authorization =
                new AuthenticationHeaderValue("Bearer", _bearerToken);

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

            // Serialize the request data to JSON
            var requestDataJson = JsonSerializer.Serialize(requestData);

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

            // Send the request and get the response
            var response = await client.SendAsync(request);

            // Check the status code of the response
            if (response.IsSuccessStatusCode)
            {
                var responseJson = await response.Content.ReadAsStringAsync();
                var link = JsonSerializer.Deserialize<string>(responseJson);
                Console.WriteLine($"Expirable link created: {link}");
            }
            else
            {
                Console.WriteLine($"Error creating expirable link. Status code: {response.StatusCode}");
            }
        }
    }
}

Python

import requests

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.json()
        print(f"Expirable link created: {link}")
    else:
        print(f"Error creating expirable link. Status code: {response.status_code}")

Node.js

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);
    }
}

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) {
    $link = json_decode($response);
    echo "Expirable link created: $link\n";
  } else {
    echo "Error creating expirable link. Status code: $http_status\n";
  }
}

Last updated