PHP
Authenticate and insert articles with cURL. Requires PHP 7.4+.
Fetch statistics
<?php
$ch = curl_init("https://your-domain.com/api/content/stats");
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
"X-API-Key: " . getenv("CONTENT_HUB_API_KEY"),
],
]);
$stats = json_decode(curl_exec($ch), true);
curl_close($ch);
echo $stats["total_content"], PHP_EOL;Insert articles
<?php
$payload = json_encode([
"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",
],
],
]);
$ch = curl_init("https://your-domain.com/api/content");
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $payload,
CURLOPT_HTTPHEADER => [
"X-API-Key: " . getenv("CONTENT_HUB_API_KEY"),
"Content-Type: application/json",
],
]);
$result = json_decode(curl_exec($ch), true);
curl_close($ch);
echo $result["message"], PHP_EOL;Never commit your keyLoad it from the environment (
getenv) or a secrets manager, never from a checked-in config file.