JavaScript / Node.js
Insert articles and pull statistics from the Content API with fetch.
Insert articles
const res = await fetch("https://your-domain.com/api/content", {
method: "POST",
headers: {
"X-API-Key": process.env.CONTENT_HUB_API_KEY,
"Content-Type": "application/json",
},
body: JSON.stringify({
articles: [
{
id: "article-123",
title: "Understanding Car Insurance",
body: "<p>Content body...</p>",
slug: "understanding-car-insurance",
status: "published",
category: "insurance",
primary_keyword: "car insurance",
},
],
}),
});
const result = await res.json();
console.log(result.message); // "Inserted 1 articles"Read statistics
const res = await fetch("https://your-domain.com/api/content/stats", {
headers: { "X-API-Key": process.env.CONTENT_HUB_API_KEY },
});
const stats = await res.json();
console.log(stats.total_content, stats.published_content);Missing or invalid keys return 401 with {"error": "Unauthorized"} — check the header before debugging anything else.