Skip to content

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

License

Notifications You must be signed in to change notification settings

papajin/activecampaign-api-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

activecampaign-api-php

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"     => "[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;
 
 }

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages