PHP code example of treehousetim / activecampaign-api-v3-wrapper

1. Go to this page and download the library: Download treehousetim/activecampaign-api-v3-wrapper library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

treehousetim / activecampaign-api-v3-wrapper example snippets




// include utoload.php';

use treehousetim\ActiveCampaign\ActiveCampaign;

// using hard coded values
$ac = new ActiveCampaign( 'ACTIVE_CAMPAIGN_URL', 'ACTIVE_CAMPAIGN_KEY');

// using environment variables
$ac = new ActiveCampaign();

// lists
$lists = $ac->lists();

// contacts
$contacts = $ac->contacts();

// tags
$tags = $ac->tags();

// custom fields
$fields = $ac->customFields();


$lists = $ac->lists()->all();


// fetch the first 50 lists
$limit = 50;
$offset = 0;

$paginated_lists = $ac->lists()->paginate( $limit, $offset )->all();

// get all contacts and sort them by email in asc order and by last name in desc order
$contacts = $ac->contacts()->orderby( ['email' => 'asc', 'lastName' => 'desc'] )->all();

// get contacts where first name is equal to John
$contacts = $ac->contacts()->filter(['firstName' => 'john'])->all();

$ac->tags()->query(['foo' => 'bar'])->all();

// get tag with ID == 1
$tag = $ac->tags()->get(1);

// skip 10 tags and get next 50 tags, also order them by description
$tags = $ac->tags()->orderby(['description' => 'asc'])->paginate(50, 10)->all();

// get contact where email is equal to '[email protected]'
$contact = $ac->contacts()->getByEmail('[email protected]');

// create new contact
$ac->contacts()->create([
  'email'     => '[email protected]',
  'firstName' => 'John',
  'lastName'  => 'Doe',
  'phone'     => '7223224241'
]);

// create new tag
$ac->tags()->create([
  'tag'         => 'My Tag',
  'tagType'     => 'contact',
  'description' => 'Description'
]);

// add tag to contact
$ac->contacts()->addTag([
  'contact' => '1', // contact ID
  'tag'     => '20' // tag ID
]);