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

1. Go to this page and download the library: Download dhrechanyi/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/ */

    

dhrechanyi / activecampaign-api-v3-wrapper example snippets




// include utoload.php';

// add namespace
use Dhrechanyi\ActiveCampaign\ActiveCampaign;

// create wrapper instance
$ac = new ActiveCampaign('YOUR_ACTIVE_CAMPAIGN_URL', 'YOUR_ACTIVE_CAMPAIGN_KEY');

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

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

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

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

// ->paginate($limit, $offset = 0)

// fetch 50 lists
$paginated_lists = $ac->lists()->paginate(50)->all();

// get all contacts and sort them by email in asc order and by last name in desc order
$contacts = $ac->contacts()->order(['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
]);