Subscriptions
Get Plans
Get a List of Plans
Get a list of plans. Use optional query parameters to filter or sort the result.
GET https://api.dyntube.com/v1/plans
Headers
| Name | Type | Description |
|---|---|---|
| Authorization | String | Bearer YOUR_API_KEY |
Query Parameters
| Name | Type | Description |
|---|---|---|
| page | Integer | Page number |
| size | Integer | Page size |
| planType | Integer | Type of the plan |
| sort | String | Sort order of the results. See details below. |
200: OK returns a list of plans and a pager.
json
{
"pager": {
"page": 1,
"totalPages": 7,
"totalResults": 7,
"sort": "Created:-1"
},
"plans": [
{
"id": "wj5XnB5Bg",
"name": "Monthly Plan",
"description": "",
"type": 1,
"storePlanType": 1,
"frequency": {
"interval": 0,
"count": 0
},
"status": 1,
"channelKeys": [
"r3KYBVcLEw"
],
"videoKeys": [],
"created": "2020-05-19T10:06:13.3099083+00:00",
"updated": "2020-05-19T10:06:13.3099082+00:00"
}
]
}Error Responses
| Status Code | Description |
|---|---|
| 400 | Bad Request - Invalid query parameters |
| 401 | Unauthorized - Invalid or missing API key |
Sorting of results
Use the sort query parameter to order results. The format is field:1 for ascending order or field:-1 for descending order.
yaml
# Here are examples to sort by "Created" date.
#Sort by date created descending:
https://api.dyntube.com/v1/plans?sort=Created:-1
#Sort by date created ascending:
https://api.dyntube.com/v1/plans?sort=Created:1Code Samples
C\#
csharp
using System;
using System.Net.Http;
using System.Threading.Tasks;
using Newtonsoft.Json;
class Program
{
static async Task Main(string[] args)
{
string url = "https://api.dyntube.com/v1/plans?sort=Created:-1";
using (var httpClient = new HttpClient())
{
httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", "YOUR_API_KEY");
var response = await httpClient.GetAsync(url);
if (response.IsSuccessStatusCode)
{
var json = await response.Content.ReadAsStringAsync();
var result = JsonConvert.DeserializeObject<PlanResponse>(json);
// Access the list of plans
var plans = result.Plans;
// Process the list of plans as needed
foreach (var plan in plans)
{
Console.WriteLine($"Plan ID: {plan.Id}, Name: {plan.Name}");
}
}
else
{
Console.WriteLine($"Failed to get plans. Status code: {response.StatusCode}");
}
}
}
}
// Define the class to hold the plan response
public class PlanResponse
{
public Pager Pager { get; set; }
public Plan[] Plans { get; set; }
}
// Define the classes to hold the plan data
public class Pager
{
public int Page { get; set; }
public int TotalPages { get; set; }
public int TotalResults { get; set; }
public string Sort { get; set; }
}
public class Plan
{
public string Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public int Type { get; set; }
public int StorePlanType { get; set; }
public Frequency Frequency { get; set; }
public int Status { get; set; }
public string[] ChannelKeys { get; set; }
public string[] VideoKeys { get; set; }
public DateTime Created { get; set; }
public DateTime Updated { get; set; }
}
public class Frequency
{
public int Interval { get; set; }
public int Count { get; set; }
}Node.js
javascript
const axios = require('axios');
const url = 'https://api.dyntube.com/v1/plans?sort=Created:-1';
axios
.get(url, { headers: { Authorization: 'Bearer YOUR_API_KEY' } })
.then(response => {
const plans = response.data.plans;
console.log(plans);
})
.catch(error => {
console.error(error.response?.data || error.message);
});Python
python
import requests
url = "https://api.dyntube.com/v1/plans?sort=Created:-1"
response = requests.get(url, headers={"Authorization": "Bearer YOUR_API_KEY"})
if response.status_code == 200:
data = response.json()
print(data)
else:
print("Failed to get plans. Status code:", response.status_code)PHP
php
<?php
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => "https://api.dyntube.com/v1/plans?sort=Created:-1",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer YOUR_API_KEY"
]
]);
$response = curl_exec($ch);
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$data = json_decode($response, true);
if ($statusCode >= 200 && $statusCode < 300) {
print_r($data["plans"]);
} else {
echo "Failed to get plans. Status code: {$statusCode}\n";
echo $response;
}
?>Related Pages
- Create a plan to add a new subscription plan.
- Delete a plan to remove or archive a plan.
- Attach plan to member to grant a member access to a plan.
Something missing or wrong here? Tell us and we will correct it. New to DynTube? Start with uploading and embedding.