/courier-php

A PHP package for communicating with the Courier REST API.

Primary LanguagePHPMIT LicenseMIT

Courier SDK

Courier PHP SDK supporting:

  • Send API
  • Messages API
  • Profiles API
  • Preferences API
  • Events API
  • Brands API
  • Lists 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 trycourier/courier

Configuration

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

$client = new CourierClient("base-url", "authorization-token", "username", "password");

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" => "courier.pigeon@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, string $brand = NULL, object $profile = NULL, object $data = NULL, object $preferences = NULL, object $override = NULL, string $idempotency_key = NULL): object [?]
  • sendNotificationToList(string $event, string $list = NULL, string $pattern = NULL, string $brand = NULL, object $data = NULL, object $override = NULL, string $idempotency_key = NULL): object [?]

Messages API

  • getMessages(string $cursor = NULL, string $event = NULL, string $list = NULL, string $message_id = NULL, string $notification = NULL, string $recipient = NULL): object [?]
  • getMessage(string $message_id): object [?]
  • getMessageHistory(string $message_id, string $type = NULL): object [?]

Lists API

  • getLists(string $cursor = NULL, string $pattern = NULL): object [?]
  • getList(string $list_id): object [?]
  • putList(string $list_id, string $name): object [?]
  • deleteList(string $list_id): object [?]
  • restoreList(string $list_id): object [?]
  • getListSubscriptions(string $list_id, string $cursor = NULL): object [?]
  • subscribeMultipleRecipientsToList(string $list_id, array $recipients): object [?]
  • subscribeRecipientToList(string $list_id, string $recipient_id): object [?]
  • deleteListSubscription(string $list_id, string $recipient_id): object [?]

Brands API

  • getBrands(string $cursor = NULL): object [?]
  • createBrand(string $id = NULL, string $name, object $settings, object $snippets = NULL, string $idempotency_key = NULL): object [?]
  • getBrand(string $brand_id): object [?]
  • replaceBrand(string $brand_id, string $name, object $settings, object $snippets = NULL): object [?]
  • deleteBrand(string $brand_id): object [?]

Events API

  • getEvents(): object [?]
  • getEvent(string $event_id): object [?]
  • putEvent(string $event_id, string $id, string $type): object [?]

Profiles API

  • getProfile(string $recipient_id): object [?]
  • upsertProfile(string $recipient_id, object $profile): object [?]
  • patchProfile(string $recipient_id, array $patch): object [?]
  • replaceProfile(string $recipient_id, object $profile): object [?]
  • getProfileLists(string $recipient_id, string $cursor = NULL): 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.