2017 © Pedro Peláez
 

library createsend-php

A php library which implements the complete functionality of the Campaign Monitor API.

image

campaignmonitor/createsend-php

A php library which implements the complete functionality of the Campaign Monitor API.

  • Tuesday, July 10, 2018
  • by jdennes
  • Repository
  • 41 Watchers
  • 241 Stars
  • 821,879 Installations
  • PHP
  • 17 Dependents
  • 0 Suggesters
  • 90 Forks
  • 24 Open issues
  • 27 Versions
  • 8 % Grown

The README.md

createsend Build Status

A PHP library which implements the complete functionality of the Campaign Monitor API., (*1)

Installation

Composer

If you use Composer, you can run the following command from the root of your project:, (*2)

composer require campaignmonitor/createsend-php

Or add campaignmonitor/createsend-php to your composer.json file:, (*3)

{
    "require": {
        "campaignmonitor/createsend-php": "{version}"
    }
}

Followed by running:, (*4)

composer update

Manual Installation

Otherwise you can simply download the library and include it in your project., (*5)

After you have installed the library, simply include the relevant API class, as follows:, (*6)

require_once 'csrest_campaigns.php'

Authenticating

The Campaign Monitor API supports authentication using either OAuth or an API key., (*7)

Using OAuth

Depending on the environment you are developing in, you may wish to use a PHP OAuth library to get access tokens for your users. If you don't use an OAuth library, you will need to get access tokens for your users by following the instructions included in the Campaign Monitor API documentation. This package provides functionality to help you do this, as described below. You may also wish to reference this example application, which is implemented using Slim but could easily be adapted for use with any PHP framework., (*8)

The first thing your application should do is redirect your user to the Campaign Monitor authorization URL where they will have the opportunity to approve your application to access their Campaign Monitor account. You can get this authorization URL by using the CS_REST_General::authorize_url() method, like so:, (*9)

require_once 'csrest_general.php';

$authorize_url = CS_REST_General::authorize_url(
    'Client ID for your application',
    'Redirect URI for your application',
    'The permission level your application requires',
    'Optional state data to be included'
);
# Redirect your users to $authorize_url.

If your user approves your application, they will then be redirected to the redirect_uri you specified, which will include a code parameter, and optionally a state parameter in the query string. Your application should implement a handler which can exchange the code passed to it for an access token, using CS_REST_General::exchange_token() like so:, (*10)

require_once 'csrest_general.php';

$result = CS_REST_General::exchange_token(
    'Client ID for your application',
    'Client Secret for your application',
    'Redirect URI for your application',
    'A unique code for your user' # Get the code parameter from the query string
);

if ($result->was_successful()) {
    $access_token = $result->response->access_token;
    $expires_in = $result->response->expires_in;
    $refresh_token = $result->response->refresh_token;
    # Save $access_token, $expires_in, and $refresh_token.
} else {
    echo 'An error occurred:\n';
    echo $result->response->error.': '.$result->response->error_description."\n";
    # Handle error...
}

At this point you have an access token and refresh token for your user which you should store somewhere convenient so that your application can look up these values when your user wants to make future Campaign Monitor API calls., (*11)

Once you have an access token and refresh token for your user, you can authenticate and make further API calls like so:, (*12)

require_once 'csrest_general.php';

$auth = array(
    'access_token' => 'your access token',
    'refresh_token' => 'your refresh_token');
$wrap = new CS_REST_General($auth);

$result = $wrap->get_clients();
var_dump($result->response);

All OAuth tokens have an expiry time, and can be renewed with a corresponding refresh token. If your access token expires when attempting to make an API call, you will receive an error response, so your code should handle this. Here's an example of how you could do this:, (*13)

require_once 'csrest_general.php';

$auth = array(
    'access_token' => 'your access token',
    'refresh_token' => 'your refresh token'
);
$wrap = new CS_REST_General($auth);
$result = $wrap->get_clients();
if (!$result->was_successful()) {
    # If you receive '121: Expired OAuth Token', refresh the access token
    if ($result->response->Code == 121) {
        list($new_access_token, $new_expires_in, $new_refresh_token) = 
            $wrap->refresh_token();
        # Save $new_access_token, $new_expires_in, and $new_refresh_token
    }
    # Make the call again
    $result = $wrap->get_clients();
}
var_dump($result->response);

Using an API key

require_once 'csrest_general.php';

$auth = array('api_key' => 'your API key');
$wrap = new CS_REST_General($auth);

$result = $wrap->get_clients();
var_dump($result->response);

API Call Timeout

You can set your local API call timeout time in createsend-php\class\transport.php line 11, in the CS_REST_CALL_TIMEOUT variable. Currently the default is 120 secs., (*14)

Examples

Samples for creating or accessing all resources can be found in the samples directory. These samples can be used as the basis for your own application and provide an outline of the expected inputs for each API call., (*15)

Further documentation of the inputs and outputs of each call can be found in the documentation in each of the csrest_*.php files or simply by examining the var_dump results in each of the provided samples., (*16)

Contributing

Please check the guidelines for contributing to this repository., (*17)

Releasing

Please check the instructions for releasing this library., (*18)

The Versions

10/07 2018

dev-master

9999999-dev http://campaignmonitor.github.io/createsend-php/

A php library which implements the complete functionality of the Campaign Monitor API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Toby Brain

api monitor campaign

25/05 2018

v6.0.0

6.0.0.0 http://campaignmonitor.github.io/createsend-php/

A php library which implements the complete functionality of the Campaign Monitor API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Toby Brain

api monitor campaign

25/05 2018

dev-consent-to-track

dev-consent-to-track http://campaignmonitor.github.io/createsend-php/

A php library which implements the complete functionality of the Campaign Monitor API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Toby Brain

api monitor campaign

21/04 2018

dev-CMINT-44

dev-CMINT-44 http://campaignmonitor.github.io/createsend-php/

A php library which implements the complete functionality of the Campaign Monitor API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Toby Brain

api monitor campaign

21/04 2018

v5.1.3

5.1.3.0 http://campaignmonitor.github.io/createsend-php/

A php library which implements the complete functionality of the Campaign Monitor API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Toby Brain

api monitor campaign

28/08 2017

dev-custom-e2e

dev-custom-e2e http://campaignmonitor.github.io/createsend-php/

A php library which implements the complete functionality of the Campaign Monitor API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Toby Brain

api monitor campaign

15/05 2017

5.1.2

5.1.2.0 http://campaignmonitor.github.io/createsend-php/

A php library which implements the complete functionality of the Campaign Monitor API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Toby Brain

api monitor campaign

31/03 2017

dev-events-v1

dev-events-v1 http://campaignmonitor.github.io/createsend-php/

A php library which implements the complete functionality of the Campaign Monitor API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Toby Brain

api monitor campaign

19/07 2016

v5.0.2

5.0.2.0 http://campaignmonitor.github.io/createsend-php/

A php library which implements the complete functionality of the Campaign Monitor API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Toby Brain

api monitor campaign

14/12 2015

v5.0.1

5.0.1.0 http://campaignmonitor.github.io/createsend-php/

A php library which implements the complete functionality of the Campaign Monitor API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Toby Brain

api monitor campaign

08/12 2015

v5.0.0

5.0.0.0 http://campaignmonitor.github.io/createsend-php/

A php library which implements the complete functionality of the Campaign Monitor API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Toby Brain

api monitor campaign

09/09 2015

v4.1.1

4.1.1.0 http://campaignmonitor.github.io/createsend-php/

A php library which implements the complete functionality of the Campaign Monitor API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Toby Brain

api monitor campaign

05/08 2015

v4.1.0

4.1.0.0 http://campaignmonitor.github.io/createsend-php/

A php library which implements the complete functionality of the Campaign Monitor API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Toby Brain

api monitor campaign

29/10 2014

v4.0.2

4.0.2.0 http://campaignmonitor.github.io/createsend-php/

A php library which implements the complete functionality of the Campaign Monitor API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Toby Brain

api monitor campaign

30/05 2014

v4.0.1

4.0.1.0 http://campaignmonitor.github.io/createsend-php/

A php library which implements the complete functionality of the Campaign Monitor API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Toby Brain

api monitor campaign

06/02 2014

v4.0.0

4.0.0.0 http://campaignmonitor.github.io/createsend-php/

A php library which implements the complete functionality of the Campaign Monitor API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Toby Brain

api monitor campaign

09/12 2013

v3.1.3

3.1.3.0 http://campaignmonitor.github.io/createsend-php/

A php library which implements the complete functionality of the Campaign Monitor API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Toby Brain

api monitor campaign

28/10 2013

v3.1.2

3.1.2.0 http://campaignmonitor.github.io/createsend-php/

A php library which implements the complete functionality of the Campaign Monitor API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Toby Brain

api monitor campaign

03/10 2013

v3.1.1

3.1.1.0 http://campaignmonitor.github.io/createsend-php/

A php library which implements the complete functionality of the Campaign Monitor API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Toby Brain

api monitor campaign

15/04 2013

v3.1.0

3.1.0.0 http://campaignmonitor.github.com/createsend-php/

A php library which implements the complete functionality of the Campaign Monitor API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Toby Brain

api monitor campaign

25/03 2013

v3.0.0

3.0.0.0 http://campaignmonitor.github.com/createsend-php/

A php library which implements the complete functionality of the Campaign Monitor API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Toby Brain

api monitor campaign

19/12 2012

v2.5.2

2.5.2.0 http://campaignmonitor.github.com/createsend-php/

A php library which implements the complete functionality of the Campaign Monitor API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Toby Brain

api monitor campaign

14/12 2012

v2.5.1

2.5.1.0 http://campaignmonitor.github.com/createsend-php/

A php library which implements the complete functionality of the Campaign Monitor API.

  Sources   Download

MIT

The Requires

  • php >=5.2.0

 

by Toby Brain

api monitor campaign

11/12 2012

v2.5.0

2.5.0.0 http://campaignmonitor.github.com/createsend-php/

A php library which implements the complete functionality of the Campaign Monitor API.

  Sources   Download

MIT

The Requires

  • php >=5.2.0

 

by Toby Brain

api monitor campaign

05/11 2012

v2.4.0

2.4.0.0 http://campaignmonitor.github.com/createsend-php/

A php library which implements the complete functionality of the Campaign Monitor API.

  Sources   Download

MIT

The Requires

  • php >=5.2.0

 

by Toby Brain

api monitor campaign

23/10 2012

v2.3.2

2.3.2.0 http://campaignmonitor.github.com/createsend-php/

A php library which implements the complete functionality of the Campaign Monitor API.

  Sources   Download

MIT

The Requires

  • php >=5.2.0

 

by Toby Brain

api monitor campaign

19/10 2012

v2.3.1

2.3.1.0 http://campaignmonitor.github.com/createsend-php/

A php library which implements the complete functionality of the Campaign Monitor API.

  Sources   Download

MIT

The Requires

  • php >=5.2.0

 

by Toby Brain

api monitor campaign