/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
  • Notifications API
  • Automations API
  • Bulk API
  • Audiences API
  • Token Management API
  • Audit Events API
  • Tenants API
  • Users 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-json

Installation

This library uses HTTPlug as HTTP client. HTTPlug is an abstraction that allows this library to support different HTTP Clients. Therefore, you need to provide it with an client and/or adapter for the HTTP library you prefer. You can find all the available adapters in Packagist. This documentation assumes you use the Guzzle Client, but you can replace it with any client that you prefer.

The recommended way to install courier-php is through Composer:

composer require trycourier/courier guzzlehttp/guzzle

Configuration

Instantiate the Courier client class with your authorization token OR username and password. Providing just an 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 endpoints. 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 (Send API)
  • sendEnhancedNotification(object $message, string $idempotency_key = NULL): object (Send API)
  • sendNotificationToList(string $event, string $list = NULL, string $pattern = NULL, string $brand = NULL, object $data = NULL, object $override = NULL, string $idempotency_key = NULL): object (Send list API)

Messages API

  • cancelMessage(string $message_id): object [?]
  • 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 [?]

Notifications API

  • listNotifications(string $cursor = NULL): object
  • getNotificationContent(string $id): object
  • getNotificationDraftContent(string $id): object
  • postNotificationVariations(string $id, array $blocks, array $channels = NULL): object
  • postNotificationDraftVariations(string $id, array $blocks, array $channels = NULL): object
  • getNotificationSubmissionChecks(string $id, string $submissionId): object
  • putNotificationSubmissionChecks(string $id, string $submissionId, array $checks): object
  • deleteNotificationSubmission(string $id, string $submissionId): object

Automations API

  • invokeAutomation(object $automation, string $brand = NULL, string $template = NULL, string $recipient = NULL, object $data = NULL, object $profile = NULL): object [?]
  • invokeAutomationFromTemplate(string $templateId, string $brand = NULL, object $data = NULL, object $profile = NULL, string $recipient = NULL, string $template = NULL): object [?]
  • getAutomationRun(string $runId): object

Bulk API

Audiences API

Token Management API

Audit Events API

Accounts API (only on v1.12.0)

Tenants API (v2.0.0+)

Users API

Errors

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