Official PHP SDK for interacting with the Knock API.

Overview

Knock PHP library

Documentation

See the documentation for PHP usage examples.

Installation

composer require knocklabs/knock-php php-http/guzzle7-adapter

Configuration

To use the library you must provide a secret API key, provided in the Knock dashboard.

use Knock\KnockSdk\Client;

$client = new Client('sk_12345');

Usage

Identifying users

$client->users()->identify('jhammond', [
    'name' => 'John Hammond',
    'email' => '[email protected]',
]);

Sending notifies (triggering workflows)

$client->notify('dinosaurs-loose', [
    // user id of who performed the action
    'actor' => 'dnedry',
    // list of user ids for who should receive the notification
    'recipients' => ['jhammond', 'agrant', 'imalcolm', 'esattler'],
    // data payload to send through
    'data' => [
        'type' => 'trex',
        'priority' => 1,
    ],
    // an optional identifier for the tenant that the notifications belong to
    'tenant' => 'jurassic-park',
    // an optional key to provide to cancel a notify
    'cancellation_key' => '21e958bb-2517-40bb-aaaa-d40acc26dac3',
]);

Retrieving users

$client->users()->get('jhammond');

Deleting users

$client->users()->delete('jhammond');

Preferences

$client->users()->setPreferences('jhammond', [
    'channel_types' => [
        'email' => true, 
        'sms' => false,
    ],
    'workflows' => [
        'dinosaurs-loose' => [
            'email' => false, 
            'in_app_feed': true,
        ]
    ]
]);

Getting and setting channel data

$knock->users()->setChannelData('jhammond', '5a88728a-3ecb-400d-ba6f-9c0956ab252f', [
    'tokens' => [
        $apnsToken
    ],
});

$knock->users()->getChannelData('jhammond', '5a88728a-3ecb-400d-ba6f-9c0956ab252f');

Canceling workflows

$client->workflows()->cancel('dinosaurs-loose', [
    'cancellation_key' => '21e958bb-2517-40bb-aaaa-d40acc26dac3'
    // optionally you can specify recipients here
    'recipients' => ['jhammond'],
]);

Signing JWTs

You can use the firebase/php-jwt package to sign JWTs easily. You will need to generate an environment specific signing key, which you can find in the Knock dashboard.

If you're using a signing token you will need to pass this to your client to perform authentication. You can read more about client-side authentication here.

use Firebase\JWT\JWT;

$privateKey = env('KNOCK_SIGNING_KEY');
$encoded = JWT::encode(['sub' => 'jhammond'], $privateKey, 'RS256');
You might also like...
A PHP SDK for the GlobalSmartOTP API.
A PHP SDK for the GlobalSmartOTP API.

GlobalSmartOTP PHP SDK A PHP SDK for the GlobalSmartOTP API. Requirements PHP 7.4 or higher cURL Installation $ git clone [email protected]:GlobalSmartOT

🤖 Telegram Bot API PHP SDK. Lets you build Telegram Bots easily! Supports Laravel out of the box.
🤖 Telegram Bot API PHP SDK. Lets you build Telegram Bots easily! Supports Laravel out of the box.

Telegram Bot API - PHP SDK Telegram Bot PHP SDK lets you develop Telegram Bots in PHP easily! Supports Laravel out of the box. Telegram Bot API is an

SDK for latest version of Telegram bots API

SDK for latest version of Telegram bots API (from April 24, 2020) Using Examples Installing composer require "DiyorbekUz/Telelib: dev-master" Init bot

Universal payments API SDK (UNOFFICIAL QIWI CLIENT)

Qiwi Php Client Especially for 🦊 Zorra Telecom and 👥 Everyone else Привет Attention: At the moment the number of methods is very limited, they will

AltiriaSmsPhpClient, the official PHP client of Altiria
AltiriaSmsPhpClient, the official PHP client of Altiria

Altiria, cliente SMS PHP Altiria SMS PHP es un cliente que simplifica al máximo la integración de nuestro API para PHP. Por el momento, esta librería

The official Previewify.app PHP Client
The official Previewify.app PHP Client

Previewify for PHP This is the official Previewify client for PHP. Support us Like our work? You can support us by purchasing one of our products. Ins

It's a PHP Application to simplify working with Google Sheets SDK for php.

About GoogleSheetsPHP It's a PHP Application to simplify working with Google Sheets SDK for php. Note: i used Slim 3 to construct the application but

A Laravel package to help integrate Shopware PHP SDK much more easier

Shopware 6 Laravel SDK A Laravel package to help integrate Shopware PHP SDK much more easier Installation Install with Composer composer require sas/s

Minter Blockchain PHP SDK

About This is a pure PHP SDK for working with Minter blockchain Installation Minter Api Methods: getBalance getNonce send getAddresses getStatus getVa

Releases(v0.1.5)
Owner
Knock
Knock
Official repository of the AWS SDK for PHP (@awsforphp)

AWS SDK for PHP - Version 3 The AWS SDK for PHP makes it easy for developers to access Amazon Web Services in their PHP code, and build robust applica

Amazon Web Services 5.7k Jan 1, 2023
Mailgun's Official SDK for PHP

Mailgun PHP client This is the Mailgun PHP SDK. This SDK contains methods for easily interacting with the Mailgun API. Below are examples to get you s

Mailgun Team 1k Dec 23, 2022
The official PHP SDK for Webmarketer (app.webmarketer.io)

PHP SDK for Webmarketer The official PHP SDK for Webmarketer (app.webmarketer.io). Install To add this package, your project must meet several require

Webmarketer 5 Dec 13, 2021
API SDK for OpenTrade Commerce API: Taobao, Alibaba, JD, 1688, Aliexpress, Ebay.

OtapiPhpClient Create Client $client = new OtClient($key, $secret, $lang); key (Access Key) secret (Secret for access key) language (2 symbol lang id

OpenTrade Commerce 5 Sep 20, 2022
PHP Telegram Bot based on the official Telegram Bot API with iTelegram Class.

iTelegram PHP Telegram Bot based on the official Telegram Bot API Bots: An introduction for developers Bots are special Telegram accounts designed to

iNeoTeam | آی نئو 5 Nov 9, 2022
Upload Vimeo video with CodeIgniter, Official PHP library for the Vimeo API

Upload Vimeo video with CodeIgniter, Official PHP library for the Vimeo API. Vimeo Video upload with API using Official PHP library for the Vimeo API.

WordPress theme and Plugins developers 2 Oct 10, 2021
A PHP client for the official Kizeo Forms API V3+. 📌

Kizeo Forms API V3+ - PHP This is a Swagger generated doc for Kizeo REST API 3. You can find additionnal documentation here : Online documentation. Th

siapepfrance 1 Oct 26, 2021
PHP Telegram Bot based on the official Telegram Bot API

PHP Telegram Bot based on the official Telegram Bot API

null 4 Dec 8, 2021
The Official Vultr API PHP Wrapper

WIP - This is not the final API Client. Unstable release use with caution. Vultr API PHP Client. Getting Started Must have a PSR7, PSR17, and PSR18 Co

Vultr 10 Dec 20, 2022
Official International Name days API library

Official International Name days API library Name day API library for nameday.abalin.net This library makes it easy to send requests towards nameday.a

VojtaN 5 Feb 25, 2022