OverviewPlatformsAPI ReferenceResources

PHP

Install zernio-dev/zernio-php with Composer and call every Zernio API endpoint from PHP 8.1 or later on Guzzle.


zernio-dev/zernio-php is the official PHP client for the Zernio API, built on Guzzle. It needs PHP 8.1 or later.

Install it with composer require zernio-dev/zernio-php. The package is on Packagist and the source on GitHub.

First call

Terminal
composer require zernio-dev/zernio-php
export ZERNIO_API_KEY="sk_..."

Set the API key on a Configuration, then construct the API class you need with a Guzzle client.

This script publishes a post to a connected LinkedIn account. accountId comes from GET /v1/accounts (list accounts).

PHP
<?php
require_once(__DIR__ . '/vendor/autoload.php');

$config = Zernio\Configuration::getDefaultConfiguration()
    ->setAccessToken(getenv('ZERNIO_API_KEY'));

$postsApi = new Zernio\Api\PostsApi(new GuzzleHttp\Client(), $config);

$linkedin = new Zernio\Model\CreatePostRequestPlatformsInner();
$linkedin->setPlatform('linkedin');
$linkedin->setAccountId('66b2e19d8c3f5a7e9d0b1c2d');

$request = new Zernio\Model\CreatePostRequest();
$request->setContent('Hello from the Zernio PHP SDK');
$request->setPlatforms([$linkedin]);
$request->setPublishNow(true);

try {
    $result = $postsApi->createPost($request);
    print_r($result);
} catch (Zernio\ApiException $e) {
    echo 'Status: ', $e->getCode(), PHP_EOL;
    echo 'Body: ', $e->getResponseBody(), PHP_EOL;
}

Response (201):

JSON
{
  "post": {
    "_id": "65f1c0a9e2b5af0012ab34cd",
    "status": "published",
    "platforms": [
      {
        "platform": "linkedin",
        "status": "published",
        "platformPostUrl": "https://www.linkedin.com/feed/update/..."
      }
    ]
  }
}

$result is a \Zernio\Model\PostCreateResponse model, not raw JSON:

  • $result->getPost() returns the post object above.
  • $result->getPost()->getPlatforms()[0]->getPlatformPostUrl() returns the published URL.

Every method returns the model for the status code it got back.

Methods

Each method is named after the operationId of the endpoint it calls, on a class per API tag in Zernio\Api:

  • PostsApi::createPost
  • AccountsApi::listAccounts
  • ProfilesApi::createProfile
  • AnalyticsApi::getAnalytics
  • WebhooksApi::createWebhookSettings
  • WorkflowsApi::createWorkflow

Request models live in Zernio\Model and use set... methods.

How it behaves

Base URL and timeout

The base URL is on Configuration, the timeout on the Guzzle client.

PHP
$config = Zernio\Configuration::getDefaultConfiguration()
    ->setAccessToken(getenv('ZERNIO_API_KEY'))
    ->setHost('https://zernio.com/api');

$postsApi = new Zernio\Api\PostsApi(new GuzzleHttp\Client(['timeout' => 30]), $config);

setHost defaults to https://zernio.com/api. Pass another URL to point at a different host.

Timeouts are Guzzle's, not the SDK's. The client you hand the API class carries them:

  • timeout, in seconds, for the whole request
  • connect_timeout for the connection

The Late\ namespace still resolves

Use the Zernio\ namespace in new code.

The legacy Late\ namespace is aliased on load, so code written against the Late SDK keeps working.

createPost accepts an idempotency key

The second argument is sent as the x-request-id header: $postsApi->createPost($request, $xRequestId).

A retry with the same value and the same content within 24 hours returns the original post instead of a duplicate-content 409.

To protect a retry whose body can differ, send an Idempotency-Key header instead (idempotency).

Errors throw Zernio\ApiException

A non-2xx response throws Zernio\ApiException. getCode() is the HTTP status and getResponseBody() the JSON envelope.

Running the first call twice within 24 hours throws it with code 409, because the same content is already published to that account:

JSON
{
  "error": "This exact content is already scheduled, publishing, or was posted to this account within the last 24 hours.",
  "details": {
    "accountId": "66b2e19d8c3f5a7e9d0b1c2d",
    "platform": "linkedin",
    "existingPostId": "65f1c0a9e2b5af0012ab34cd"
  }
}

Change the content, or send an idempotency key. The error handling guide lists every code.

Was this page helpful?

On this page