DynTube API
  • Welcome!
  • Key Concepts
  • Quick Start
  • Reference
    • Videos
      • Video Upload via File (Server Side)
      • Video Upload via URL (server side)
      • HTML-Form Client Side Video Uploads
      • Get Video Status
      • Get Videos
      • Get Video
      • Update Video
      • Delete Video
      • Download Original Video
      • Get Video for Mobile App/Custom Player
      • Update Video Image
      • Add Video Captions/Chapters/Subtitles
      • Delete Video Captions/Subtitles/Chapters
      • Create Expirable Links
      • Get Collected Emails
      • Setting Up Webhooks
      • Copy call-to-action (CTA) to Videos
      • Token Authentication
    • Projects
      • Create Project
      • Update a Project
      • Get Projects
      • Get a Project
      • Delete a Project
      • Set default CTA for Project
    • Live Streaming
      • Create a Live Stream
      • Update a Live Stream
      • Get Live Streams
      • Get a Live Stream
      • Count Live Streams
      • Live Streams Limit
      • Get Live Streaming Recording
      • Delete a Live Stream
      • Service and Regions for live streams
    • Channels
      • Get Channels
      • Get Channel
      • Delete Channel
    • Subscriptions
      • Create a Plan
      • Create a Member
      • Attach Plan To Member
      • Get Plans
      • Get Members
      • Get Member's Plans
      • Delete a Plan
    • Analytics
      • Use your User Ids in Analytics
      • Get Video Analytics
    • Javascript Events Methods
      • Plain Javascript Events & Methods
      • Control the Player using React
      • Control the Player in Vue.js
    • Developer Resources
      • How to embed DynTube player in Next.Js
      • How to embed the video player in React
      • How to play DynTube videos in React Native
      • ExoPlayer app to play HLS videos
      • How to embed videos & channels dynamically
      • How to Import Vimeo Videos into DynTube
Powered by GitBook
On this page
  • Create a New Plan
  • To create a new plan.
  • Sample JSON Body
  • Code Samples
  • C#
  • Node.js
  • Python
  • PHP
  1. Reference
  2. Subscriptions

Create a Plan

Create a New Plan

To create a new plan.

POST https://api.dyntube.com/v1/plans

The content type of the HTTP request should be application/json. Please have a look at the sample JSON body below.

Sample JSON Body

Here is a sample JSON request to create a plan.

    {
        
        "name": "Video Plan",
        "description": "This is my first video plan",
        "type":3, // 1 for purchase, 3 for rental
        "frequency":{
            "interval":1,
            "count":10
        },
        "status":1,
        "startDate" : "YYYY-MM-DDThh:mm:ss" // UTC DATE TIME
        "channelKeys":["key1,key2"],
        "videoKeys":["key1,key2"]
    }

Code Samples

C#

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

namespace VideoPlan
{
    class Program
    {
        static async Task Main(string[] args)
        {
            var httpClient = new HttpClient();
            httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", "YOUR_BEARER_TOKEN");

            var request = new HttpRequestMessage(HttpMethod.Post, "https://api.dyntube.com/v1/plans");

            var requestBody = new
            {
                name = "Video Plan",
                description = "This is my first video plan",
                type = 3,
                frequency = new
                {
                    interval = 1,
                    count = 10
                },
                status = 1,
                channelKeys = new string[] { "key1", "key2" },
                videoKeys = new string[] { "key1", "key2" }
            };

            var jsonRequestBody = JsonSerializer.Serialize(requestBody);
            request.Content = new StringContent(jsonRequestBody, Encoding.UTF8, "application/json");

            var response = await httpClient.SendAsync(request);

            if (response.IsSuccessStatusCode)
            {
                var responseContent = await response.Content.ReadAsStringAsync();
                var plan = JsonSerializer.Deserialize<Plan>(responseContent);
                Console.WriteLine($"Plan created with ID {plan.id}.");
            }
            else
            {
                Console.WriteLine($"Failed to create plan. Status code: {response.StatusCode}");
            }
        }
    }

    public class Plan
    {
        public string id { get; set; }
        public string name { get; set; }
        public string description { get; set; }
        public int type { get; set; }
        public Frequency frequency { get; set; }
        public int status { get; set; }
        public string[] channelKeys { get; set; }
        public string[] videoKeys { get; set; }
    }

    public class Frequency
    {
        public int interval { get; set; }
        public int count { get; set; }
    }
}

Node.js

const axios = require('axios');

const data = {
  name: 'Video Plan',
  description: 'This is my first video plan',
  type: 3, // 1 for purchase, 3 for rental
  frequency: {
    interval: 1,
    count: 10
  },
  status: 1,
  channelKeys: ['key1', 'key2'],
  videoKeys: ['key1', 'key2']
};

axios.post('https://api.dyntube.com/v1/plans', data)
  .then(response => {
    console.log('Plan created:', response.data);
  })
  .catch(error => {
    console.error('Failed to create plan:', error.response.data);
  });

Python

import requests
import json

# set up payload with desired data
payload = {
    "name": "Video Plan",
    "description": "This is my first video plan",
    "type": 3, # 1 for purchase, 3 for rental
    "frequency": {
        "interval": 1,
        "count": 10
    },
    "status": 1,
    "channelKeys": ["key1", "key2"],
    "videoKeys": ["key1", "key2"]
}

# set up request headers and API endpoint
headers = {
    "Authorization": "Bearer YOUR_BEARER_TOKEN_HERE",
    "Content-Type": "application/json"
}
url = "https://api.dyntube.com/v1/plans"

# send the POST request to create the video plan
response = requests.post(url, headers=headers, data=json.dumps(payload))

# check response status code
if response.status_code == 200:
    plan_id = response.json().get("id")
    print(f"Video plan with ID {plan_id} created successfully.")
else:
    print(f"Failed to create video plan. Status code: {response.status_code}")
py

PHP

<?php
// This code sends an HTTP POST request to create a new video plan on DynTube.

$url = "https://api.dyntube.com/v1/plans";
$accessToken = "YOUR_ACCESS_TOKEN";

$data = array(
    "name" => "Video Plan",
    "description" => "This is my first video plan",
    "type" => 3, // 1 for purchase, 3 for rental
    "frequency" => array(
        "interval" => 1,
        "count" => 10
    ),
    "status" => 1,
    "channelKeys" => array("key1,key2"),
    "videoKeys" => array("key1,key2")
);

// Set headers
$headers = array(
    "Authorization: Bearer " . $accessToken,
    "Content-Type: application/json",
    "Accept: application/json"
);

// Encode the data in JSON format
$dataJson = json_encode($data);

// Initialize cURL session
$ch = curl_init();

// Set cURL options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataJson);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

// Execute the cURL session
$response = curl_exec($ch);

// Check for errors
if(curl_errno($ch)) {
    echo 'Error: ' . curl_error($ch);
} else {
    // Decode the JSON response
    $responseData = json_decode($response, true);

    // Print the video plan ID
    echo "Video plan created with ID: " . $responseData["id"];
}

// Close the cURL session
curl_close($ch);
?>

PreviousSubscriptionsNextCreate a Member

Last updated 6 months ago