Download the PHP package ilrwebservices/campaign-monitor-rest-api-client without Composer
On this page you can find all versions of the php package ilrwebservices/campaign-monitor-rest-api-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ilrwebservices/campaign-monitor-rest-api-client
More information about ilrwebservices/campaign-monitor-rest-api-client
Files in ilrwebservices/campaign-monitor-rest-api-client
Package campaign-monitor-rest-api-client
Short Description PHP library for the CampaignMonitor 'createsend' API
License MIT
Homepage https://github.com/ilrWebServices/campaignmonitor-api-php
Informations about the package campaign-monitor-rest-api-client
Campaign Monitor REST API Client for PHP
A simple PHP http client for the Campaign Monitor REST API. Optimized for JSON and authentication via API key. Based on Guzzle.
CampaignMonitorRestClient
is an extended GuzzleHttp\Client
, so it can do all the things that Guzzle can and a bit more.
Be sure to refer to the Campaign Monitor API documentation for details.
Installation
Via composer:
Usage
Note how the API key is passed into the client constructor options along with other Guzzle-compatible options. In this example, the API key is stored in an environment variable since it is sensitive information that should not be stored in code.
The CampaignMonitorRestClient
will set the base_uri
option to https://api.createsend.com/api/v3.2/
automatically. To use a different base uri (for example for a different API version), you can specify it explicitly:
You can now make API calls just as you would in Guzzle:
Since the base_uri
option is pre-configured, you can use a relative URL (be sure not to add a leading /
, though):
And because it's Guzzle, there are shorthand methods:
Responses are PSR-7 response messages, just like Guzzle, so you can get returned data via getBody()
:
For application/json
responses, CampaignMonitorRestClient
adds a non-standard getData()
method that decodes the JSON response for you:
Be careful with large responses, however, as they can consume too much memory.
Sending JSON data to API endpoints can be done using the json
request option from Guzzle:
Error handling
You can use Guzzle exceptions for error handling. Campaign Montior endpoints generally use 4xx codes for errors, so GuzzleHttp\Exception\ClientException
is a good match for catching those errors.
If the above request to create a new client failed, a GuzzleHttp\Exception\ClientException
would be thrown and the following output displayed:
Inspired by drewm/mailchimp-api.