Official PHP SDK for ContentPulse.io - content rendering, API client, and publishing utilities.
- PHP 8.2+
composer require contentpulse/contentpulse-phpThe only required argument is your API key. When baseUrl is omitted, the SDK
resolves it (in order) from:
- The
CONTENTPULSE_BASE_URLPHP constant (if defined) - The
CONTENTPULSE_BASE_URLenvironment variable - The default
https://contentpulse.io
use ContentPulse\Http\ContentPulseClient;
// Minimal: uses CONTENTPULSE_BASE_URL (env/constant) or defaults to https://contentpulse.io
$client = new ContentPulseClient(apiKey: 'your-api-key');
// Or override explicitly:
$client = new ContentPulseClient(
apiKey: 'your-api-key',
baseUrl: 'https://contentpulse.io',
);The SDK performs a single HTTP request per call - it does not loop,
retry, or usleep. Callers are expected to apply their own retry policy
when needed.
use ContentPulse\WordPress\Support\ContentPulseEndpointResolver;
$apiBaseUrl = ContentPulseEndpointResolver::resolveApiBaseUrlFromEnvironment();
$appBaseUrl = ContentPulseEndpointResolver::resolveAppBaseUrlFromEnvironment();
$publishEndpoint = ContentPulseEndpointResolver::buildPublishWordPressEndpoint($apiBaseUrl, $contentId);
$contentUrl = ContentPulseEndpointResolver::buildContentUrl($appBaseUrl, $contentId);When no overrides are provided, the resolver auto-selects sensible defaults:
- Local/dev:
http://contentpulse.test:8080andhttp://app.contentpulse.test:5173(whencontentpulse.testis resolvable) - Otherwise:
https://contentpulse.ioandhttps://app.contentpulse.io
Overrides (highest to lowest precedence): explicit argument → PHP constant (CONTENTPULSE_API_URL, CONTENTPULSE_APP_URL) → environment variable.
use ContentPulse\Core\DTO\ContentFilters;
$feed = $client->getContentFeed(new ContentFilters(
websiteId: 1,
perPage: 20,
));
foreach ($feed->items as $item) {
// $item contains content metadata and structure
}use ContentPulse\Rendering\HtmlRenderer;
$renderer = new HtmlRenderer();
$html = $renderer->renderAll($content->sections);use ContentPulse\Rendering\SectionNormalizer;
$normalizer = new SectionNormalizer();
$normalized = $normalizer->normalize($rawSections);use ContentPulse\Core\DTO\SeoMeta;
$seo = SeoMeta::fromArray($content->seo_metadata);
$html = $seo->toHtml(); // Renders <title>, meta description, og:*, twitter:*Build platform-specific payloads for WordPress or Shopify:
use ContentPulse\Publishing\PublishPayloadBuilder;
use ContentPulse\Rendering\HtmlRenderer;
$builder = new PublishPayloadBuilder(new HtmlRenderer());
$payload = $builder->buildForWordPress($content);
// or
$payload = $builder->buildForShopify($content);| Module | Purpose |
|---|---|
Core/Contracts/ |
Interfaces for API client, renderers, and publishers |
Core/DTO/ |
Data transfer objects (CompatibilityInfo, PublicationRecord, SeoMeta, PublishResult) |
Core/Exceptions/ |
Exception hierarchy for API and validation errors |
Http/ |
REST API client for ContentPulse endpoints |
Rendering/ |
HtmlRenderer, SectionNormalizer, SEO meta renderer |
Publishing/ |
Publish payload builder for WordPress, Shopify, and custom platforms |
The HtmlRenderer supports all section types produced by the ContentPulse content generation pipeline:
Fixed sections: titles, hero, cta, seo_keywords, references
Content sections: content, content_seo, conclusion
Component sections: steps, table, grid, checklist, faq, dos_donts, alert, quote, pros_cons, summary_box, definition, key_stats, tip_box, comparison_card, comparison_table, timeline, accordion, testimonial, code_snippet
composer testOr directly:
./vendor/bin/phpunitMIT