Subscriptions
Create a Plan
Create a New Plan
Create a new subscription plan for paid video or channel access.
POST https://api.dyntube.com/v1/plans
Send the request body as application/json. The example below shows the expected payload.
Headers
| Name | Type | Description |
|---|---|---|
| Authorization | String | Bearer YOUR_API_KEY |
| Content-Type | String | application/json |
Sample Request Body
Here is a sample JSON request to create a plan.
json
{
"name": "Video Plan",
"description": "This is my first video plan",
"type": 3,
"frequency": {
"interval": 1,
"count": 10
},
"status": 1,
"startDate": "2026-05-28T00:00:00Z",
"channelKeys": ["key1", "key2"],
"videoKeys": ["key1", "key2"]
}Code Samples
C\#
csharp
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_API_KEY");
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
javascript
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, {
headers: { Authorization: 'Bearer YOUR_API_KEY' }
})
.then(response => {
console.log('Plan created:', response.data);
})
.catch(error => {
console.error('Failed to create plan:', error.response?.data || error.message);
});Python
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_API_KEY",
"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}")PHP
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);
?>Common Next Steps
After creating a plan:
- Create a member for the viewer who should receive access.
- Attach plan to member to grant access to the plan.
- Get plans to list and verify available plans.
- Manage member plan lifecycle to pause, resume, or cancel access later.
Something missing or wrong here? Tell us and we will correct it. New to DynTube? Start with uploading and embedding.