Slack API in PHP: Plain curl vs jolicode/slack-php-api (Tested Code)
Two tested ways to call the Slack API from PHP: plain curl with a bot token, and the jolicode/slack-php-api client. We ran both on PHP 8.5 on 5 November 2026, posted a message, read history and caught a bad channel ID. Code and output below.
On this page
To use the Slack API from PHP, send an HTTPS request with a bot token to a method such as https://slack.com/api/chat.postMessage, either with PHP's curl functions or with jolicode/slack-php-api, the PHP client Slack lists among its community tools. Slack has no official PHP SDK. On 5 November 2026 we ran both on PHP 8.5.12 with Composer 2.11.1 against a test workspace: posted a message, read the channel history with a cursor and sent to a channel that does not exist. The scripts and their real output are below.
Which PHP package to use
We read the main packages on Packagist on 5 November 2026:
| Package | Latest release | Downloads | What it covers |
|---|---|---|---|
jolicode/slack-php-api | v4.10.0, 2026-09-25 | 5,389,209 | The whole Web API, generated from Slack's spec |
alek13/slack | 2.4.0, 2026-08-07 | 6,245,105 | Incoming webhooks only (a maintained fork of maknz/slack) |
maknz/slack | 1.7.0, 2015-06-03 | 12,324,526 | Incoming webhooks only, no release since 2015 |
slack-php/slack-app-framework | 1.0.0, 2022-02-24 | 35,417 | A Bolt-style app framework, no release since 2022 |
For one-way alerts into one channel, an incoming webhook needs no package at all; our webhook curl examples work the same from PHP's curl. For anything that reads, replies or picks the channel per message, use a bot token as below.
Setup
Create a Slack app with a bot user and the scopes chat:write and channels:history, install it, and copy the Bot User OAuth Token (xoxb-); our Slack bot token guide shows where it is. Invite the bot to the channel. Then, for the client:
composer require jolicode/slack-php-api symfony/http-client nyholm/psr7
The client does not bring its own HTTP library. It needs a PSR-18 HTTP client and PSR-7 messages, which is what the two extra packages are.
1. Plain curl
<?php
$ch = curl_init('https://slack.com/api/chat.postMessage');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('SLACK_BOT_TOKEN'),
'Content-Type: application/json; charset=utf-8',
],
CURLOPT_POSTFIELDS => json_encode([
'channel' => getenv('SLACK_CHANNEL'),
'text' => 'Hello from PHP (curl)',
]),
]);
$res = json_decode(curl_exec($ch), true);
echo $res['ok'] ? "ok ts={$res['ts']}\n" : "error: {$res['error']}\n";
Never appear "away" on Slack again
Cloud-based. No downloads. Works 24/7 even when your laptop is off.
2. jolicode/slack-php-api
<?php
require __DIR__ . '/vendor/autoload.php';
use JoliCode\Slack\ClientFactory;
use JoliCode\Slack\Exception\SlackErrorResponse;
$client = ClientFactory::create(getenv('SLACK_BOT_TOKEN'));
$channel = getenv('SLACK_CHANNEL');
$msg = $client->chatPostMessage(['channel' => $channel, 'text' => 'Hello from PHP (jolicode/slack-php-api)']);
echo 'posted ts=' . $msg->getTs() . "\n";
$history = $client->conversationsHistory(['channel' => $channel, 'limit' => 2]);
foreach ($history->getMessages() as $m) {
echo ' history: ' . $m->getTs() . ' ' . $m->getText() . "\n";
}
echo ' next_cursor: ' . ($history->getResponseMetadata()?->getNextCursor() ?: '(none)') . "\n";
try {
$client->chatPostMessage(['channel' => 'C000BAD', 'text' => 'x']);
} catch (SlackErrorResponse $e) {
echo get_class($e) . ': ' . $e->getErrorCode() . "\n";
}
The output
We ran the curl script twice, the second time with the channel set to C000BAD, then the client script:
--- curl
ok ts=1793864866.824929
--- curl bad channel
error: channel_not_found
--- jolicode
posted ts=1793864867.220519
history: 1793864867.220519 Hello from PHP (jolicode/slack-php-api)
history: 1793864866.824929 Hello from PHP (curl)
next_cursor: bmV4dF90czoxNzkzODY0NzI1MzcyMzE5
JoliCode\Slack\Exception\SlackErrorResponse: channel_not_found
Both posts arrived from the bot, one under the other:
The two styles report errors differently. Slack answers a bad call with HTTP 200 and "ok": false, which plain curl hands to you as data, so your code has to check ok every time. The jolicode client turns the same answer into a SlackErrorResponse exception, and getErrorCode() gives the Slack error string. If the error is missing_scope, our missing_scope guide explains the fix.
The client also returns typed objects: getTs() on the posted message, getMessages() on the history, and getResponseMetadata()->getNextCursor() for the next page. Pass that value as cursor in the next conversationsHistory call until it comes back empty, as in our guide to getting messages from a channel.
Things that tripped us up
- • Method names follow Slack's with the dot removed and camel case:
chat.postMessageischatPostMessage,conversations.historyisconversationsHistory. - • Arguments go in as an array with Slack's own field names (
channel,text,limit,cursor), not as PHP named arguments.
FAQ
Is there an official Slack SDK for PHP?
No. Slack's official SDKs cover Python, Node.js and Java. Slack's list of community tools names jolicode/slack-php-api for the Web API.
Can I verify Slack requests in PHP without a package?
Yes. Slack signs each request with your signing secret; compare hash_hmac('sha256', "v0:$timestamp:$body", $secret) with the X-Slack-Signature header using hash_equals. Our Slack signing secret guide covers the details.
Stop Jiggling Your Mouse.
Join hundreds of remote workers who never worry about their Slack status. Set it up once, stay green forever.
Related Articles
Slack Progress Bar: Block Kit, Emoji and chat.update, Tested
Block Kit has no progress bar element, so a Slack progress bar is text you redraw with chat.update. We drew one three ways on 9 November 2026, timed every update, and pushed chat.update until Slack answered ratelimited.
Slack Channel Welcome Message: A Tested Bot and the Free-Plan Catch
Slack has no built-in welcome message per channel, and Workflow Builder is closed to Free workspaces. A 30-line Bolt app that listens for member_joined_channel does the job on any plan. We ran it on 9 November 2026 and timed the welcome.
Can a Slack Webhook Send a File? What We Tested, and What Works
An incoming webhook cannot upload a file. It can show an image from a public URL in an image block, or a link Slack unfurls. For a real file you need a bot token and the upload API. Every payload we tried on 9 November 2026, with Slack's answer.