PHP code example of thiio / active-campaign-php-sdk

1. Go to this page and download the library: Download thiio/active-campaign-php-sdk 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/ */

    

thiio / active-campaign-php-sdk example snippets



//YOUR ACTIVE CAMPAIGN CREDENTIALS
$url = "<https://YOUR_USER.api-us1.com>";
$key = "<YOUR_TOKEN_KEY>";

//Initialize a new instance of active campaign library class
$client = new ActiveCampaign();
$client->initialize($url, $key);

/* 
Instanciate a contact model and add values to the attributes specified on:

https://developers.activecampaign.com/reference#contact 

*/
$contact = new ActiveCampaignContact();
$contact->setEmail("[email protected]");
$contact->setFirstName("Jhon");
$contact->setLastName("Doe");
$contact->setPhone("+529985656464");

//Fetch contacts class and perform the create request
$contacts = $client->contacts();

try{
    //Perform create request sending the contact model
     $response = $contacts->create($contact);
    
    //If response success var_dump all content
    if($response->success){
    
        echo "Contact successfully created \n";
        var_dump($response->body->contact);
        
    }else{
        //If any error or message is present print it out
        if(isset($response->body->message)){
            echo $message;
        }
        if(isset($response->body->errors)){
            foreach($response->body->errors as $error){
                echo $error->title."\n";
                echo $error->detail."\n";
                echo $error->code."\n";
            }
        }
        
    }
}catch(Exception $e){
    echo $e->getMessage();
}