OmniSocialsOmniSocials
DocumentationAPI reference
Help centerSupport
  • Documentation
  • API reference
Developers
  • Quickstart
  • API reference
  • SDKs
  • MCP server
  • CLI
For AI agents
  • Docs for AI agents
  • llms.txt
  • OpenAPI spec
  • Postman collection
Product
  • OmniSocials
  • Pricing
  • Changelog
  • Help center
Company
  • Support
  • Privacy policy
  • Terms of service

© 2026 OmniSocials

OmniSocials on GitHubOmniSocials on XOmniSocials on LinkedIn
Overview
Get started
SDKs
    Node.jsPythonGoRubyJavaPHP.NETRust
CLI
MCPDocs for AI agentsWebhooks
Guides
Platforms
Integrations
Connect
Migrate
Plans and billing
GlossaryChangelogAPI reference
SDKs

PHP SDK reference: install, auth and methods

The official PHP SDK. PHP 8.1+, no Composer dependencies (ext-curl, ext-json), Stripe-style resource objects with associative-array params.

This page is the reference. For an overview of the PHP SDK, see omnisocials.com/sdk/php.

Install

TerminalTerminal
composer require omnisocials/omnisocials-php

Authentication

PHP
use OmniSocials\Client; $client = new Client(apiKey: 'omsk_live_...');

Reads OMNISOCIALS_API_KEY if omitted. A missing key throws OmniSocials\Exception\AuthenticationException.

Create a post

PHP
$response = $client->posts->create([ 'content' => 'New drop this Friday', 'channels' => ['instagram', 'facebook', 'linkedin'], 'scheduled_at' => '2026-08-01T09:00:00Z', 'media_urls' => ['https://example.com/teaser.jpg'], ]); echo $response['data']['id'] . ' ' . $response['data']['status'];

Any media_urls (or media_ids) entry can also be an array carrying per-media alt text (max 1500 chars), delivered to Mastodon, Bluesky, X (photos), Pinterest, Instagram (images), and LinkedIn (images):

PHP
'media_urls' => [['url' => 'https://example.com/teaser.jpg', 'alt' => 'Red sneaker on a white background']],

Publish immediately:

PHP
$client->posts->createAndPublish([ 'content' => 'Going live right now', 'channels' => ['x', 'bluesky'], ]);

Upload media

PHP
$upload = $client->media->uploadFromUrl([ 'url' => 'https://example.com/launch-video.mp4', 'name' => 'launch-video-v2', 'folder' => 'Campaigns', ]); echo $upload['data']['id']; print_r($upload['compatibility']);

Local files via multipart: a file on disk as path, raw bytes as contents:

PHP
// From a path $client->media->upload(['path' => './photos/product.jpg', 'name' => 'product-hero']); // Or from raw bytes (pass a filename so the API can detect the type) $bytes = file_get_contents('./photos/product.jpg'); $client->media->upload(['contents' => $bytes, 'filename' => 'product.jpg']);

A string in file is raw contents and is never opened as a path; one that names an existing file is refused (use path).

Analytics

PHP
// One post's latest per-platform metrics $stats = $client->analytics->post('post_id'); print_r($stats['data']['platforms']['instagram']['metrics'] ?? null); // Batch: up to 100 posts in one call $batch = $client->analytics->posts(['id1', 'id2', 'id3']); // Workspace-wide overview $overview = $client->analytics->overview(['period' => '30d']); echo $overview['data']['total_impressions'] . ' ' . $overview['data']['total_engagements']; // Account-level stats (followers etc) $accountStats = $client->analytics->accounts(['platform' => 'instagram']);

X statistics

X bills every statistics read, so these calls can use credits. See X statistics and credits for the prices and the rules. accounts:write and credits:read are opt-in: the Credits and X statistics switch when you create the key, and billing rights for the key's creator.

PHP
// How often an X account is read: posts full / light / off, followers daily / weekly / off $client->accounts->update('1234_x', ['x_statistics' => ['posts' => 'light']]); // "Update now": read one post's X numbers now $fresh = $client->analytics->refreshPost(9123); echo $fresh['data']['credits_used'], "\n"; // The balance and the X statistics use $credits = $client->credits->get()['data']; echo $credits['balance'], ' ', $credits['x_statistics']['total_credits_month'], "\n";

Post tags

Tags are your workspace's own labels for posts (a hook style, a format), to filter and compare them. They never go to a platform. Set them with tags on posts->create() and posts->update() (ids or names; a new name becomes a tag; on update null or [] removes them), or on many posts at once with tags->apply().

PHP
$client->tags->create(['name' => 'Question', 'color' => 'blue']); $client->tags->list(); $client->tags->apply([ 'post_ids' => ['1024', '1025'], 'add' => ['Question'], ]); // Filter by tag (id or name, comma separated = any of them) $client->posts->list(['tag' => 'Question']); $client->analytics->overview(['period' => '30d', 'tag' => 'Question']); // How each tag did against your normal (vs_normal 0.38 = 38% above) $compare = $client->analytics->tags(['platform' => 'tiktok']); print_r($compare['data']['tags']);

Limits and feature requests

$client->limits->list() (GET /limits) lists what OmniSocials cannot do, why, and what to do instead. $client->featureRequests->create() sends a request to the OmniSocials team for the person who owns the key, so send it only after the person agrees; a platform rule answers 409 not_requestable and stores nothing. More in Limits and feature requests.

PHP
$limits = $client->limits->list(['platform' => 'tiktok']); foreach ($limits['data'] as $limit) { echo $limit['title'], ': ', $limit['says'], ' ', $limit['instead'] ?? '', "\n"; } // Only after the person agrees $result = $client->featureRequests->create([ 'summary' => 'Post our daily update to the Announcements topic of our Telegram group.', 'platform' => 'telegram', 'limit_id' => 'telegram.forum_topics', ]); echo $result['outcome'], ' ', $result['data']['id'], "\n"; // 'created', 'voted' (a vote on your organisation's open request) or 'already_requested' $mine = $client->featureRequests->list(); // newest first, with status and team_replies

Social Inbox

Read and answer DMs, comments and mentions from your connected accounts. The API key needs the opt-in inbox:read / inbox:write scopes. The lists use cursor pagination (cursor in, pagination.next_cursor out).

PHP
$conversations = $client->inbox->listConversations(['platform' => 'instagram', 'unread' => true]); $conversationId = $conversations['data'][0]['conversation_id']; $messages = $client->inbox->getMessages($conversationId); $client->inbox->reply($conversationId, ['text' => 'Thanks for reaching out!']); $client->inbox->markRead($conversationId); // Comment moderation: hide (['hide' => false] unhides) or delete $client->inbox->hide($messages['data'][0]['id']); $client->inbox->deleteMessage($messages['data'][0]['id']);

next() hands out the next conversation that still needs an answer, with the thread and the post it belongs to. On a comment thread, pass message_id so the reply goes under the comment you answer and not under the newest comment on the post. On a Facebook comment, 'mention_author' => true tags the commenter: the reply starts with their name as a clickable link, and the answer carries mention with the result (tagged, plain_name, failed or unverified).

PHP
$next = $client->inbox->next(); while ($next['data'] !== null) { $message = $next['data']['message']; if (!$next['data']['reply_window']['open']) { // An Instagram/Facebook DM past Meta's 24-hour window: answer it in the app $client->inbox->markRead($message['conversation_id']); $next = $client->inbox->next(); continue; } $reply = $client->inbox->reply($message['conversation_id'], [ 'text' => 'Thanks! DM sent.', 'message_id' => $message['id'], 'include_next' => true, ]); $next = ['data' => $reply['next'] ?? null, 'remaining' => $reply['remaining'] ?? 0]; }

See the Social Inbox guide for the platforms, the reply rules and the error codes.

Pinterest product tags

Tag products on a Pin so people can shop the items in the image. List the product Pins of the connected Pinterest account, then pass up to 24 of their Pin ids as product_tags in the pinterest options of the post. Only product Pins of your own account can be tagged; products of other merchants cannot.

PHP
$result = $client->pinterest->listProducts(); if (isset($result['error'])) { error_log($result['error']['code'] . ': ' . $result['error']['message']); } else { $client->posts->create([ 'content' => 'Our summer picks', 'channels' => ['pinterest'], 'media_urls' => ['https://example.com/summer-look.jpg'], 'scheduled_at' => '2026-08-01T09:00:00Z', 'pinterest' => [ 'board_id' => '1234567890', 'product_tags' => array_column(array_slice($result['products'], 0, 3), 'pin_id'), ], ]); }

The list answers with HTTP 200 in both cases: products on success, or an error array (pinterest_not_connected, pinterest_catalog_access_required, platform_error) when it could not be read. It reads the Pinterest catalog when the connection has catalog access (given one time in the OmniSocials composer: Pinterest options, Add products, Connect catalog), else the account's own Pins. The tags are added right after the Pin is published. A product that Pinterest refuses never fails the post: the post then carries pinterest.product_tags_result with the tagged and the skipped Pin ids. $client->pinterest->validateProduct($id) checks one Pin id or Pin link before you post. On posts->update() the pinterest array replaces the stored one, so leave product_tags out to remove the tags.

Approve or reject a post

Pass the step you reviewed: the current_step of the post's approval review. When the review is on another step now (somebody decided since you read it, or a retried call already went through), nothing is decided and the call fails with 409 step_changed; error.current_step_order in the error body is the step the review is on now. Without a step the call acts on whatever step is current. approve($id) and reject($id, $comment) still work.

PHP
use OmniSocials\Exception\ApiException; $review = $client->posts->getApproval($id)['data']; try { $client->posts->approve($id, stepOrder: $review['current_step']); // or: $client->posts->reject($id, 'Wrong CTA link', stepOrder: $review['current_step']); } catch (ApiException $e) { if ($e->getErrorCode() !== 'step_changed') { throw $e; } // The review moved on; nothing was decided. Read the approval again. }

Verify webhooks

PHP
<?php require __DIR__ . '/vendor/autoload.php'; use OmniSocials\Webhooks; use OmniSocials\Exception\WebhookVerificationException; $payload = file_get_contents('php://input'); // the raw body, untouched $signature = $_SERVER['HTTP_X_OMNISOCIALS_SIGNATURE'] ?? ''; try { $event = Webhooks::verifySignature( $payload, $signature, getenv('OMNISOCIALS_WEBHOOK_SECRET'), 300 // tolerance in seconds (default) ); } catch (WebhookVerificationException $e) { http_response_code(400); exit; } switch ($event['type']) { case 'post.published': error_log('Published: ' . $event['data']['post_id']); break; case 'post.failed': error_log('Failed: ' . $event['data']['post_id']); break; case 'post.rejected': error_log('Rejected: ' . $event['data']['post_id'] . ' ' . ($event['data']['approval']['reason'] ?? '')); break; } http_response_code(200);

Events: post.scheduled, post.published, post.failed, post.approved and post.rejected. The two approval events carry data.approval with status, decided_by (the approver's user id) and reason (null on post.approved). To read the full review of a post (steps, approvers, the rejection reason and the comment thread), call $client->posts->getApproval($id).

Rotate the secret without missing deliveries

For 24 hours after $client->webhooks->rotateSecret($id), every delivery also carries X-OmniSocials-Signature-Previous, signed with the old secret (same format, same timestamp and body). Verify X-OmniSocials-Signature with the new secret and, when that fails, the Previous header with the old one:

PHP
try { $event = Webhooks::verifySignature($payload, $_SERVER['HTTP_X_OMNISOCIALS_SIGNATURE'] ?? '', $newSecret); } catch (WebhookVerificationException $e) { $previous = $_SERVER['HTTP_X_OMNISOCIALS_SIGNATURE_PREVIOUS'] ?? ''; if ($previous === '') { throw $e; } $event = Webhooks::verifySignature($payload, $previous, $oldSecret); }

Errors

The base class is OmniSocials\Exception\OmniSocialsException. ApiException exposes getStatus(), getErrorCode(), getMessage(), and getBody(). Types: ValidationException (400/422), AuthenticationException (401), PermissionDeniedException (403), NotFoundException (404), RateLimitException (429, getRetryAfter()), ServerException (5xx), ApiConnectionException, and WebhookVerificationException.

PHP
use OmniSocials\Exception\ApiConnectionException; use OmniSocials\Exception\ApiException; use OmniSocials\Exception\RateLimitException; use OmniSocials\Exception\ValidationException; try { $client->posts->create(['content' => 'Hi', 'channels' => ['instagram']]); } catch (RateLimitException $e) { echo 'Rate limited, retry in ' . $e->getRetryAfter() . "s\n"; } catch (ValidationException $e) { echo "Bad request ({$e->getErrorCode()}): {$e->getMessage()}\n"; print_r($e->getBody()); } catch (ApiConnectionException $e) { echo 'Network problem: ' . $e->getMessage() . "\n"; } catch (ApiException $e) { echo "API error {$e->getStatus()} ({$e->getErrorCode()}): {$e->getMessage()}\n"; }

Note the error code accessor is getErrorCode(), not getCode().

Configuration

PHP
$client = new Client( apiKey: 'omsk_live_...', baseUrl: 'https://api.omnisocials.com/v1', // default timeout: 30.0, // per-request timeout in seconds (default 30) maxRetries: 2, // automatic retries on 429 / 5xx / network errors (default 2) );

Notes

  • Responses are decoded to associative arrays
  • Webhook verification is the static Webhooks::verifySignature() using hash_equals
  • Source: github.com/OmniSocials/omnisocials-php
Last modified on December 2, 2026
Java.NET
On this page
  • Install
  • Authentication
  • Create a post
  • Upload media
  • Analytics
    • X statistics
  • Post tags
  • Limits and feature requests
  • Social Inbox
  • Pinterest product tags
  • Approve or reject a post
  • Verify webhooks
    • Rotate the secret without missing deliveries
  • Errors
  • Configuration
  • Notes
PHP
PHP
PHP
PHP
PHP
PHP
PHP
PHP
PHP
PHP
PHP
PHP
PHP
PHP
PHP
PHP
PHP
PHP