PHP SDK
This topic provides instructions for installing the Constant Contact V3 PHP SDK.
Requirements
Requires PHP 7.4 or later.
Install
You can choose to install the bindings manually or using Composer.
Install Bindings Manually
- Download the files.
- Include
autoload.php:
<?php
require_once('/path/to/constant-contact-api/vendor/autoload.php');Install Bindings Using Composer
- Run
composer require constantcontactpublicapi/constant-contact-v3api-client-php - Run
composer install
Example
The following code example uses the AddAccountEmailAddress method to create a new account email address in a Constant Contact account.
<?php
require_once(__DIR__ . '/vendor/autoload.php');
// Configure OAuth2 access token for authorization: oauth2_access_code
$config = ConstantContactApi\Client\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN');
// Configure OAuth2 access token for authorization: oauth2_implicit
$config = ConstantContactApi\Client\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN');
$apiInstance = new ConstantContactApi\Client\Api\AccountServicesApi(
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
// This is optional, `GuzzleHttp\Client` will be used as default.
new GuzzleHttp\Client(),
$config
);
$add_account_email_address_request = new \ConstantContactApi\Client\Model\AddAccountEmailAddressRequest(); // \ConstantContactApi\Client\Model\AddAccountEmailAddressRequest | A JSON request payload containing the new email address you want to add to the Constant Contact account.
try {
$result = $apiInstance->addAccountEmailAddress($add_account_email_address_request);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling AccountServicesApi->addAccountEmailAddress: ', $e->getMessage(), PHP_EOL;
}Learn More
To learn more about this SDK, visit:
-
Our PHP GitHub repository.
-
The Packagist Org.