Channels
List templates
Retrieve all channel templates available to your account. Templates define the visual styling and layout of your channels.
http
GET /v1/channels/templatesResponse
Success Response
Status Code: 200 OK
json
[
{
"key": "tmpl_modern_dark",
"name": "Modern Dark",
"planType": 2,
"status": 1,
"created": "2024-01-01T00:00:00Z"
},
{
"key": "tmpl_clean_light",
"name": "Clean Light",
"planType": 2,
"status": 1,
"created": "2024-01-01T00:00:00Z"
},
{
"key": "tmpl_minimal",
"name": "Minimal",
"planType": 1,
"status": 1,
"created": "2024-01-01T00:00:00Z"
}
]Response Fields
| Field | Type | Description |
|---|---|---|
| key | string | Unique template identifier (use in templateKey field when creating/updating channels) |
| name | string | Human-readable template name |
| planType | integer | Minimum plan type required to use this template |
| status | integer | Template status (1 = Active, available for use) |
| created | datetime | Template creation date (ISO 8601) |
Plan Types
| Value | Plan |
|---|---|
| 1 | Free |
| 2 | Pro |
| 3 | Business |
| 4 | Enterprise |
Error Responses
| Status Code | Description |
|---|---|
| 401 | Unauthorized - Invalid or missing API key |
| 500 | Internal Server Error |
Code Examples
cURL
bash
curl -X GET "https://api.dyntube.com/v1/channels/templates" \
-H "Authorization: Bearer YOUR_API_KEY"JavaScript
javascript
const response = await fetch(
'https://api.dyntube.com/v1/channels/templates',
{
headers: {
'Authorization': 'Bearer YOUR_API_KEY'
}
}
);
const templates = await response.json();
console.log('Available templates:');
templates.forEach(template => {
console.log(`- ${template.name} (${template.key})`);
});Python
python
import requests
response = requests.get(
'https://api.dyntube.com/v1/channels/templates',
headers={'Authorization': 'Bearer YOUR_API_KEY'}
)
templates = response.json()
print('Available templates:')
for template in templates:
print(f"- {template['name']} ({template['key']})")PHP
php
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.dyntube.com/v1/channels/templates');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer YOUR_API_KEY'
]);
$response = curl_exec($ch);
curl_close($ch);
$templates = json_decode($response, true);
echo "Available templates:\n";
foreach ($templates as $template) {
echo "- " . $template['name'] . " (" . $template['key'] . ")\n";
}C#
csharp
using System.Net.Http;
using System.Net.Http.Headers;
var client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "YOUR_API_KEY");
var response = await client.GetAsync("https://api.dyntube.com/v1/channels/templates");
var body = await response.Content.ReadAsStringAsync();
Console.WriteLine(body);Use Cases
Get Templates for UI Dropdown
javascript
async function getTemplateOptions() {
const response = await fetch(
'https://api.dyntube.com/v1/channels/templates',
{ headers: { 'Authorization': 'Bearer YOUR_API_KEY' } }
);
const templates = await response.json();
// Convert to options format for a dropdown/select
return templates
.filter(t => t.status === 1) // Only active templates
.map(t => ({
value: t.key,
label: t.name
}));
}
// Usage in React
const templateOptions = await getTemplateOptions();
// [
// { value: 'tmpl_modern_dark', label: 'Modern Dark' },
// { value: 'tmpl_clean_light', label: 'Clean Light' }
// ]Filter Templates by Plan
javascript
async function getTemplatesForPlan(userPlanType) {
const response = await fetch(
'https://api.dyntube.com/v1/channels/templates',
{ headers: { 'Authorization': 'Bearer YOUR_API_KEY' } }
);
const templates = await response.json();
// Filter templates available for the user's plan
return templates.filter(t =>
t.status === 1 && t.planType <= userPlanType
);
}
// Get templates available for a Pro user (planType = 2)
const availableTemplates = await getTemplatesForPlan(2);Create Channel with Selected Template
javascript
async function createChannelWithTemplate(name, videoKeys, templateKey) {
// First, verify the template exists
const templatesResponse = await fetch(
'https://api.dyntube.com/v1/channels/templates',
{ headers: { 'Authorization': 'Bearer YOUR_API_KEY' } }
);
const templates = await templatesResponse.json();
const templateExists = templates.some(t => t.key === templateKey);
if (!templateExists) {
throw new Error(`Template "${templateKey}" not found`);
}
// Create the channel with the template
const response = await fetch('https://api.dyntube.com/v1/channels', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
name,
videoKeys,
templateKey
})
});
return response.json();
}
// Usage
const channel = await createChannelWithTemplate(
'My Styled Channel',
['vid_abc123', 'vid_def456'],
'tmpl_modern_dark'
);Cache Templates
javascript
class TemplateCache {
constructor(ttlMinutes = 60) {
this.cache = null;
this.lastFetch = null;
this.ttl = ttlMinutes * 60 * 1000;
}
async getTemplates() {
const now = Date.now();
// Return cached data if still valid
if (this.cache && this.lastFetch && (now - this.lastFetch < this.ttl)) {
return this.cache;
}
// Fetch fresh data
const response = await fetch(
'https://api.dyntube.com/v1/channels/templates',
{ headers: { 'Authorization': 'Bearer YOUR_API_KEY' } }
);
this.cache = await response.json();
this.lastFetch = now;
return this.cache;
}
invalidate() {
this.cache = null;
this.lastFetch = null;
}
}
// Usage
const templateCache = new TemplateCache(60); // Cache for 60 minutes
const templates = await templateCache.getTemplates();Template Usage Notes
Default Behavior
If no templateKey is specified when creating a channel:
- The channel will use the default system template
- The templateKey field in the channel response will be empty
Template Availability
- Templates are tied to your account's plan type
- Higher-tier plans have access to more templates
- Custom templates may be available for Enterprise accounts
Changing Templates
To change a channel's template, use the Update Channel endpoint and specify a new templateKey.
See Also
- Create Channel - Create a channel with a template
- Update Channel - Change a channel's template
- Channels API Overview - API overview and authentication
Something missing or wrong here? Tell us and we will correct it. New to DynTube? Start with uploading and embedding.