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.

{
    "pager": {
        "page": 1,
        "size": 12,
        "hits": 12,
        "total": 1300,
        "pages": 109
    },
    "views": [
        {
            "id": "NZDSFhZ2",
            "videoKey": "NN8GgcLjTsbUg",
            "accountKey": "8t9ym1JSJuCZg",
            "projectKey": "5lCohVbzSymGw",
            "channelKey": "tEOqkbUhB6NOw",
            "channelViewId": "NggYmvRvw",
            "planType": 1,
            "viewerId": "kQdFThzl6e0",
            "viewId": "8LsRTyu2S",
            "date": "2020-08-01T12:42:14.08+00:00",
            "region": "use-s",
            "started": true,
            "ended": false,
            "muted": false,
            "duration": 150,
            "watchTime": 0,
            "browser": {
                "family": "Firefox",
                "major": 82,
                "minor": 0
            },
            "device": {
                "family": "Other",
                "brand": "",
                "model": "",
                "type": "Desktop"
            },
            "os": {
                "family": "Windows",
                "major": 10,
                "processor": "x64"
            },
            "geo": {
                "ip": "121.121.60.0",
                "city": "Kuala Lumpur",
                "country": "MY",
                "region": "Kuala Lumpur",
                "continent": "AS"
            },
            "embed": {
                "url": "https://www.dyntube.com/",
                "domain": "www.dyntube.com",
                "type": 1
            },
            "userKey": ""
        }
		
    ]
}

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,
        "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);
?>

Last updated