JavaScript Examples
Node.js and browser examples for Content Hub API
List Domains
const apiKey = 'YOUR_API_KEY';
fetch('https://api.content-hub.net/api/domains', {
headers: {
'Authorization': `Bearer ${apiKey}`
}
})
.then(res => res.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));Create Content
const apiKey = 'YOUR_API_KEY';
const contentData = {
title: 'My Article',
content: 'Article content here',
domain: 'example.com',
slug: 'my-article',
meta_description: 'Article description'
};
fetch('https://api.content-hub.net/api/content', {
method: 'POST',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(contentData)
})
.then(res => res.json())
.then(data => console.log('Created:', data))
.catch(error => console.error('Error:', error));Update Content
const apiKey = 'YOUR_API_KEY';
const contentId = 'content-123';
const updates = {
title: 'Updated Title',
content: 'Updated content'
};
fetch(`https://api.content-hub.net/api/content/${contentId}`, {
method: 'PUT',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(updates)
})
.then(res => res.json())
.then(data => console.log('Updated:', data))
.catch(error => console.error('Error:', error));Delete Content
const apiKey = 'YOUR_API_KEY';
const contentId = 'content-123';
fetch(`https://api.content-hub.net/api/content/${contentId}`, {
method: 'DELETE',
headers: {
'Authorization': `Bearer ${apiKey}`
}
})
.then(res => res.json())
.then(data => console.log('Deleted:', data))
.catch(error => console.error('Error:', error));