digs/courier-sdk-php

PHP implementation of Courier's API as an SDK. With additional support for Laravel 5.8+

v0.10 2020-03-01 23:52 UTC

This package is auto-updated.

Last update: 2024-04-09 11:30:55 UTC


README

Courier PHP SDK supporting:

  • Send API
  • Messages API
  • Profiles API
  • Preferences API

Official Courier API docs

For a full description of request and response payloads and properties, please see the official Courier API docs.

Requirements

  • PHP 7.2+
  • ext-curl
  • ext-json

Installation

composer require digs/courier-sdk-php

Configuration

Instantiate the Courier client class with your authorization and (optional) username. Providing just a authorization token will generate a "Bearer" authorization header, while providing a username will generate a "Basic" (base64-encoded) authorization header

$client = new Courier("authorization-token", "username");

Options

Many methods allow the passing of optional data to the Courier endoint. This data should be an associative array of key/value pairs. The exact options supported are dependent on the endpoint being called. Please refer to the official Courier documentation for more information.

$profile = [
	"firstname" => "Johnny",
	"lastname" => "Appleseed",
	"email" => "johnny.appleseed@mail.com"
];

Methods

For a full description of request and response payloads and properties, please see the official Courier API docs.

Send API

  • sendNotification(string $event, string $recipient, array $profile = [], array $data = [], array $preferences = [], array $overrides = []): object [?]

Messages API

  • getMessage(string $message_id): object [?]

Profiles API

  • getProfile(string $recipient_id): object [?]
  • upsertProfile(string $recipient_id, array $profile_attributes): object [?]
  • replaceProfile(string $recipient_id, array $profile_attributes): object [?]
  • patchProfile(string $recipient_id, array $patch): object [?]

Preferences API

  • getPreferences(string $recipient_id, string $preferred_channel): object [?]
  • updatePreferences(string $recipient_id, string $preferred_channel): object [?]

Errors

All unsuccessfull (non 2xx) responses will throw a CourierRequestException. The full response object is available via the getResponse() method.