contentzen/sdk-php

Official PHP SDK for ContentZen CMS

Maintainers

Package info

github.com/contentzen-hub/sdk-php

pkg:composer/contentzen/sdk-php

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2025-07-31 13:23 UTC

This package is auto-updated.

Last update: 2026-03-29 01:13:20 UTC


README

Official PHP SDK for ContentZen CMS. Easily fetch and render content in Laravel and other PHP-based frameworks.

Installation

Install via Composer:

composer require contentzen/sdk-php

Usage

Initialize the Client

use ContentZen\Client;

// For public endpoints (no authentication required)
$client = new Client();

// For private endpoints (API token required)
$client = new Client('your_api_token_here');

Fetch Public Documents

$documents = $client->documents()->getPublicDocuments('collection-uuid', [
    'limit' => 10,
    'offset' => 0,
    'state' => 'published',
]);

Fetch a Public Document

$document = $client->documents()->getPublicDocument('collection-uuid', 'document-uuid');

Fetch Private Documents (API Token Required)

$documents = $client->documents()->getDocuments('collection-uuid', [
    'limit' => 10,
    'offset' => 0,
]);

Fetch a Private Document (API Token Required)

$document = $client->documents()->getDocument('collection-uuid', 'document-uuid');

Error Handling

All SDK methods throw ContentZen\Exception on error. Example:

use ContentZen\Exception;

try {
    $documents = $client->documents()->getDocuments('collection-uuid');
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}

Collections

// List collections
$collections = $client->collections()->getCollections();

// Get a collection
$collection = $client->collections()->getCollection('collection-uuid');

// Create a collection
$new = $client->collections()->createCollection([
    'name' => 'products',
    'display_name' => 'Products',
    'description' => 'Product catalog',
    'is_public' => false,
    'fields' => [
        ['name' => 'title', 'type' => 'string', 'display_name' => 'Product Title', 'required' => true],
        ['name' => 'price', 'type' => 'number', 'display_name' => 'Price', 'required' => true],
    ]
]);

// Update a collection
$updated = $client->collections()->updateCollection('collection-uuid', [
    'display_name' => 'Updated Products',
    'description' => 'Updated product catalog',
    'is_public' => true,
]);

// Delete a collection
$client->collections()->deleteCollection('collection-uuid');

// Get collection schema
$schema = $client->collections()->getCollectionSchema('collection-uuid');

// Get collection fields
$fields = $client->collections()->getCollectionFields('collection-uuid');

// Get field types
$fieldTypes = $client->collections()->getFieldTypes();

Media

// List media
$media = $client->media()->listMedia();

// Upload media
$uploaded = $client->media()->uploadMedia('/path/to/file.jpg');

// Get media file
$file = $client->media()->getMedia('media-uuid');

// Delete media file
$client->media()->deleteMedia('media-uuid');

Webhooks

// List webhooks
$webhooks = $client->webhooks()->listWebhooks();

// Create webhook
$newWebhook = $client->webhooks()->createWebhook([
    'url' => 'https://example.com/webhook',
    'event' => 'document.published',
]);

// Update webhook
$updatedWebhook = $client->webhooks()->updateWebhook('webhook-uuid', [
    'url' => 'https://example.com/new-webhook',
]);

// Delete webhook
$client->webhooks()->deleteWebhook('webhook-uuid');

Resources

License

MIT