papajin/activecampaign-api-php

This is unofficial PHP wrapper for the ActiveCampaign API v3. For the time being we start with Contact entity only.

v1.3.2 2021-11-03 09:54 UTC

This package is auto-updated.

Last update: 2024-05-29 04:41:03 UTC


README

Source Code Latest Version Software License

About

This is unofficial PHP wrapper for the ActiveCampaign API v3. For the time being we start with Contact entity only.

Installation

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

Requirements

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.

Examples

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"     => "john_doe@gmail.com",
        "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;
 
 }