PHP code example of datomatic / laravel-active-campaign
1. Go to this page and download the library: Download datomatic/laravel-active-campaign 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/ */
datomatic / laravel-active-campaign example snippets
return [
'base_url' => env('ACTIVE_CAMPAIGN_BASE_URL'),
'api_key' => env('ACTIVE_CAMPAIGN_API_KEY'),
// Request timeout, in seconds.
'timeout' => 100,
// How many times a request is attempted before giving up.
// Only connection errors, 429 and 5xx responses are retried.
'retry_times' => 3,
// How long to wait between two attempts, in milliseconds.
'retry_sleep' => 1000,
// Map your ActiveCampaign custom field ids to the names you want to use in your code.
'custom_fields' => [
// 'is_email_verified' => 50,
],
];
ActiveCampaign::contacts()->list(limit: 100, offset: 200); // one page, explicitly
ActiveCampaign::contacts()->count(); // total matching records
ActiveCampaign::contacts()->paginate(perPage: 50); // LengthAwarePaginator, for views
ActiveCampaign::contacts()->lazy(); // LazyCollection over every page
ActiveCampaign::contacts()->all(); // Collection over every page
ActiveCampaign::contacts()->tags(1); // the contactTag rows of contact 1
ActiveCampaign::contacts()->tag(1, 5); // apply tag 5 to contact 1
ActiveCampaign::contacts()->untag(1, 5); // throws if the contact is not tagged
ActiveCampaign::contacts()->tryUntag(1, 5); // no-op if the contact is not tagged
ActiveCampaign::contacts()->getContactTagId(1, 5); // ?int
use Datomatic\ActiveCampaign\Enums\ListStatus;
ActiveCampaign::contacts()->lists(1); // current subscriptions, with their status
ActiveCampaign::contacts()->updateListStatus(1, [
2 => ListStatus::Subscribed,
3 => ListStatus::Unsubscribed,
]);
ActiveCampaign::contacts()->automations(1); // automations the contact is in
ActiveCampaign::contacts()->addToAutomation(1, 42);
ActiveCampaign::contacts()->removeFromAutomation(1, 42); // throws if the contact is not in it
ActiveCampaign::contacts()->tryRemoveFromAutomation(1, 42);
ActiveCampaign::contacts()->getContactAutomationId(1, 42); // ?int
$status = ActiveCampaign::import()->statusOf($result['batchId']); // ?BulkImportStatus
if ($status?->isFinished()) {
$info = ActiveCampaign::import()->status($result['batchId']);
$info['success']; // ids of the contacts created
$info['failure']; // emails the API rejected
}
ActiveCampaign::import()->info(); // outstanding and recently completed batches, account wide
ActiveCampaign::automations()->list();
ActiveCampaign::automations()->get(42);
ActiveCampaign::contactAutomations()->add(1, 42); // same as contacts()->addToAutomation()
ActiveCampaign::contactAutomations()->list('filters[automation]=42');
use Datomatic\ActiveCampaign\Enums\NoteRelType;
ActiveCampaign::notes()->createNote('Called them back', 7); // a contact
ActiveCampaign::notes()->createNote('Budget approved', $deal['id'], NoteRelType::Deal);
ActiveCampaign::notes()->createNote('Renewal in March', $account['id'], NoteRelType::Account);
use Datomatic\ActiveCampaign\Enums\TagType;
ActiveCampaign::tags()->list();
ActiveCampaign::tags()->createTag('customer', 'a paying user');
ActiveCampaign::tags()->createTag('header', '', TagType::Template);
ActiveCampaign::tags()->updateTag(1, 'customer', 'updated description');
ActiveCampaign::tags()->delete(1);
ActiveCampaign::fields()->createOptions(34, ['Sales', 'Engineering']);
ActiveCampaign::fields()->options(34); // Collection of the field's options
ActiveCampaign::fields()->relate(34, 1); // relate field 34 to list 1
ActiveCampaign::fields()->relate(34); // relate it to every list
ActiveCampaign::fields()->relations(34); // Collection of the field's list relations
// Set custom field 3 of contact 7
ActiveCampaign::fieldValues()->createFieldValue(7, 3, 'Rome');
ActiveCampaign::fieldValues()->updateFieldValue(1, 3, 'Milan');
ActiveCampaign::fieldValues()->list('filters[fieldid]=3');
ActiveCampaign::fieldValues()->delete(1);
use Datomatic\ActiveCampaign\Exceptions\ActiveCampaignException;
try {
ActiveCampaign::contacts()->get(999999);
} catch (ActiveCampaignException $e) {
// The request to "contacts/999999" generated this error: [{"title":"No Result found ..."}]
report($e);
}