JavaScript Examples
Node.js and browser examples for Content Hub API
List Pages
const apiKey = 'YOUR_API_KEY';
fetch('https://api.contenhub.co/api/content', {
headers: {
'Authorization': `Bearer ${apiKey}`
}
})
.then(res => res.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));Create Page with CTA
const apiKey = 'YOUR_API_KEY';
const contentData = {
title: 'Get a Free Quote',
content: 'Tell us what you need and we will get back to you.',
slug: 'free-quote',
meta_description: 'Request a free quote today.',
cta: {
type: 'button',
label: 'Request Quote',
url: 'https://example.com/quote'
}
};
fetch('https://api.contenhub.co/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 Page
const apiKey = 'YOUR_API_KEY';
const contentId = 'content-123';
const updates = {
title: 'Updated Title',
content: 'Updated content'
};
fetch(`https://api.contenhub.co/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 Page
const apiKey = 'YOUR_API_KEY';
const contentId = 'content-123';
fetch(`https://api.contenhub.co/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));