This document covers the basics of using SDK for PHP. For detailed documentation, please refer to the resources in ./lib directory:
- Client - methods and factories to create API Client
- Client Debugging - how to get detailed information from API Client for development purposes
- Collect list - getting lists of resources, with defining queries and sort fields
- Resource details - getting single resource with details
- Create resources - defining data models and creating resources
- Delete resources - deleting resources
- Updating resources - updating resources
-
PHP 5.5+
-
Composer or 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
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.
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.
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.
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.
To get a response, call:
$response = $client->call($operation);
To determine if a response was successful, use:
$response->isSuccess();
To get HTTP status of response, use:
$response->getResponse()->getStatusCode();
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.