This is unofficial PHP wrapper for the ActiveCampaign API v3. For the time being we start with Contact entity only.
The preferred method of installation is via Packagist and Composer. Run the following command to install the package and add it as a requirement to your project's composer.json
:
composer require papajin/activecampaign-api-php
The library uses Guzzle library for http calls. Version ~6.0 is stable version for the moment. The PHP version (5.6.38) is used in our environment (due to some legacy code restrictions). The package was also working OK with PHP version 7.2. Operation of the package with other PHP versions not tested.
Please, refer to the API docs for the parameters and responses structure.
<?php
require 'vendor/autoload.php';
use papajin\ActiveCampaign\AC\Contact;
use \GuzzleHttp\Exception\ClientException;
const AC_API_PROJECT = 'https://account.api-us1.com';
const AC_API_KEY = 'somelongstringherewithyourkey';
$ac_contact = Contact::instance( AC_API_PROJECT, AC_API_KEY );
/* OR $contact = Contact::instance( new \GuzzleHttp\Client( $options ) ); */
$id = 7;
try {
// Get data for contact with id 7
$response_body = $ac_contact->show( $id );
$contact = $response_body->contact;
$geoIps = $response_body->geoIps; // ...and so on.
// Create contact
$data = [
"email" => "[email protected]",
"firstName" => "John",
"lastName" => "Doe",
];
$response_body = $ac_contact->create( $data );
} catch ( ClientException $e ) {
// Something wrong on the service side
if( 404 == $e->getCode() )
echo 'Not found exception: ' . $e->getMessage() . PHP_EOL;
elseif ( 403 == $e->getCode() )
echo 'Check that valid token provided: ' . $e->getMessage() . PHP_EOL;
}
catch ( RuntimeException $e ) {
// Something wrong on your side
echo 'Caught exception: ' . $e->getMessage() . PHP_EOL;
}