Search by

postia / postia-php

kvlkstudio

Official PHP SDK for the Postia social media publishing API.

Package info

github.com/Postia-SDK/postia-php

pkg:composer/postia/postia-php

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.1.0 2026-12-04 00:28 UTC

This package is auto-updated.

Last update: 2026-12-04 00:29:39 UTC


README

Official Postia SDK

Official PHP SDK for the Postia API. Lightweight and dependency-free beyond PHP's standard ext-curl and ext-json extensions.

Requires PHP 8.1+.

Installation

composer require postia/postia-php

Quick Start

<?php

require __DIR__ . '/vendor/autoload.php';

use Postia\Client;
use Postia\PostiaException;

$client = new Client('pst_live_your_api_key');

try {
    // Check account, key, limits, and credits
    $me = $client->getMe();
    echo 'Credits: ' . $me['credits'] . PHP_EOL;

    // List connected channels
    $channels = $client->listChannels();

    // Create a post with an Idempotency-Key
    $post = $client->createPost([
        'text' => 'Hello from PHP!',
        'channel_ids' => [$channels['data'][0]['channel_id']],
    ], idempotencyKey: 'post-create-001');

    echo 'Created post: ' . $post['post_id'] . PHP_EOL;
} catch (PostiaException $e) {
    echo sprintf(
        "API error %d (%s): %s [request_id=%s]\n",
        $e->getStatus(),
        $e->getErrorCode() ?? 'unknown',
        $e->getTitle(),
        $e->getRequestId() ?? 'n/a',
    );
    print_r($e->getErrors());
}

Configuration

$client = new Client(
    apiKey: 'pst_live_...',
    baseUrl: 'https://pub.postia.app',
    timeoutSeconds: 30,
);

Nullable Fields on Updates

When calling updatePost(), omitted keys preserve their existing value while explicit null clears nullable fields (title, signature_id, watermark_id, folder_id, cross_post, repeat):

$client->updatePost($postId, [
    'title' => 'Updated title',
    'folder_id' => null, // explicitly clears folder_id
], idempotencyKey: 'update-001');

Error Handling (RFC 9457)

All 4xx/5xx API responses throw Postia\PostiaException parsed from application/problem+json:

  • $e->getStatus() — HTTP status code (400, 402, 422, 429, ...)
  • $e->getErrorCode() — trailing code from type URI (e.g. validation_failed, credits_exhausted)
  • $e->getProblemType() — full problem type URI
  • $e->getTitle() / $e->getDetail() — summary and detail text
  • $e->getRequestId() — request_id / X-Request-Id
  • $e->getErrors() — list of ['field' => string, 'message' => string]
  • $e->getRetryAfter() — Retry-After seconds if provided

Webhook Signature Verification

$rawBody = file_get_contents('php://input');
$signature = $_SERVER['HTTP_POSTIA_SIGNATURE'] ?? '';

if (!Client::verifyWebhookSignature($rawBody, $signature, 'whsec_...')) {
    http_response_code(400);
    exit('Invalid signature');
}

Endpoint Coverage

Area Methods
Account getMe, listChannels
Posts listPosts, createPost, getPost, updatePost, deletePost, publishPost, schedulePost
Media startUpload, completeUpload, addMediaFromUrl
Analytics getAnalytics
Webhooks listWebhooks, createWebhook, getWebhook, updateWebhook, deleteWebhook, rotateWebhookSecret, testWebhook, listWebhookDeliveries, redeliverWebhook

License

MIT — see LICENSE.