/sdk-php

GetResponse SDK PHP

Primary LanguagePHPMIT LicenseMIT

GetResponse APIv3 PHP SDK

This document covers the basics of using SDK for PHP. For detailed documentation, please refer to the resources in ./lib directory:

Requirements

  • PHP 5.5+

  • cURL

  • Composer or git

SDK installation

By git

We recommend the composer installation. However, you can get SDK PHP by cloning the git project:


git clone https://github.com/GetResponse/sdk-php.git

Installing Composer

Copy composer.json from the examples directory into your project directory and run the composer install command in this directory.

You can also integrate with an existing one by running

composer require getresponse/sdk-php

See https://getcomposer.org for in-depth tutorials.

Creating client

To create a GetResponse client object, use:

use Getresponse\Sdk\GetresponseClientFactory;

$client = GetresponseClientFactory::createWithApiKey('1234567e590706d0a3e7e5a30053e456');

API_KEY should be defined in the environment variable. You should define it in the global environment, command line of the script, or by putenv() during the startup of your framework (where do I find the API Key?)

Please see the GetResponseClientFactory class from PHP SDK for other factories.

Enterprise users

For the Enterprise environment please use one of the Enterprise factories, e.g.:

use Getresponse\Sdk\GetresponseClientFactory;

$client = GetresponseClientFactory::createEnterprisePLWithApiKey('1234567e590706d0a3e7e5a30053e456', 'myexampledomain.com');

or:

use Getresponse\Sdk\GetresponseClientFactory;

$client = GetresponseClientFactory::createEnterpriseUSWithApiKey('1234567e590706d0a3e7e5a30053e456', 'myexampledomain.com');

You have to provide the domain registered in GetResponse. Please see the GetResponseClientFactory class from Getresponse\Sdk namespace for other functions and other authorization methods.

Processing single and multiple operations

To send a single operation (request), you have to create an operation object (possibly with params) and send by defined client.

Example:

// create $client first
$campaignsOperation = new GetCampaigns();
$response = $client->call($campaignsOperation);

As a result, you will get a response object.

You can send multiple operations with one request. This will speed up operations with parallel processing. Please note that throttling limits will apply (refer to API limit and throttling documentation).

// create $client first
$operationsArray = array($operation1, $operation2, $operation3);
$responsesCollection = $client->callMany($operationsArray);

As a result, you will get a collection of responses. The responses are in the same order as the operations in an array.

Handling responses

To get a response, call:

$response = $client->call($operation);

Checking response status

To determine if a response was successful, use:

$response->isSuccess();

To get HTTP status of response, use:

$response->getResponse()->getStatusCode();

Response data

The response is compatible with PSR-7.

Examples:

To get the data from response (in array format):

$response->getData();

To get unprocessed data, from a response (in a serialized JSON format):

$response->getResponse()->getBody()->getContents();

To get the response size:

$response->getResponse()->getBody()->getSize();

To get the pagination data:

$response->isPaginated();

$response->getPaginationValues();

Refer to GetResponse API documentation.