PHP code example of papajin / activecampaign-api-php

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

    

papajin / activecampaign-api-php example snippets



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;
 
 }
bash
composer