Laravel ActiveCampaign (WIP)
This package provides a simple interface to the ActiveCampaign API v3.
Currently the packages only supports the endpoints Contacts
, Custom Fields Values
and Tags
. Feel free to PR the remaining endpoints.
Requirements
- PHP 8.x
- Laravel 9.x
Installation
1. Install the package via composer
composer require label84/laravel-active-campaign
2. Publish the config file
php artisan vendor:publish --provider="Label84\ActiveCampaign\ActiveCampaignServiceProvider" --tag="config"
3. Add the base URL and API key to your .env
ACTIVE_CAMPAIGN_BASE_URL=
ACTIVE_CAMPAIGN_API_KEY=
Usage
Contacts
Retreive an existing contact by their id
use Label84\ActiveCampaign\ActiveCampaign;
$contact = resolve(ActiveCampaign::class)->contacts()->get(1);
List all contact, search contacts, or filter contacts by query defined criteria
use Label84\ActiveCampaign\ActiveCampaign;
$contacts = resolve(ActiveCampaign::class)->contacts()->list('[email protected]');
Create a contact and get the contact id
use Label84\ActiveCampaign\ActiveCampaign;
$contactId = resolve(ActiveCampaign::class)->contacts()->create('[email protected]', [
'firstName' => 'John',
'lastName' => 'Doe',
'phone' => '+3112345678',
]);
Update an existing contact
use Label84\ActiveCampaign\ActiveCampaign;
use Label84\ActiveCampaign\DataObjects\ActiveCampaignContact;
$contact = new ActiveCampaignContact(1, '[email protected]', '+3112345678', 'John', 'Deer');
$contact = resolve(ActiveCampaign::class)->contacts()->update($contact);
Delete an existing contact by their id
use Label84\ActiveCampaign\ActiveCampaign;
resolve(ActiveCampaign::class)->contacts()->delete(1);
Custom Field Values
Retreive an existing field value by their id
use Label84\ActiveCampaign\ActiveCampaign;
$fieldValue = resolve(ActiveCampaign::class)->fieldValues()->get(50);
Create a field value and get the id
use Label84\ActiveCampaign\ActiveCampaign;
$fieldValue = resolve(ActiveCampaign::class)->fieldValues()->create(1, 50, 'active');
Update an existing field value
use Label84\ActiveCampaign\ActiveCampaign;
use Label84\ActiveCampaign\DataObjects\ActiveCampaignFieldValue;
$fieldValue = new ActiveCampaignFieldValue(1, 50, 'inactive');
$fieldValue = resolve(ActiveCampaign::class)->fieldValues()->update($fieldValue);
Delete an existing field value by their id
use Label84\ActiveCampaign\ActiveCampaign;
resolve(ActiveCampaign::class)->fieldValues()->delete(50);
Tags
Retreive an existing tag by their id
use Label84\ActiveCampaign\ActiveCampaign;
$tag = resolve(ActiveCampaign::class)->tags()->get(100);
List all tags filtered by name
use Label84\ActiveCampaign\ActiveCampaign;
$tags = resolve(ActiveCampaign::class)->tags()->list('abc');
Create a tag and get the id
use Label84\ActiveCampaign\ActiveCampaign;
$tag = resolve(ActiveCampaign::class)->tags()->create('test_tag', 'This is a new tag');
Update an existing tag
use Label84\ActiveCampaign\ActiveCampaign;
use Label84\ActiveCampaign\DataObjects\ActiveCampaignTag;
$tag = new ActiveCampaignTag(100, 'test_tag', 'Another description');
$tag = resolve(ActiveCampaign::class)->tags()->update($tag);
Delete an existing tag by their id
use Label84\ActiveCampaign\ActiveCampaign;
resolve(ActiveCampaign::class)->tags()->delete(100);
Tests
./vendor/bin/phpstan analyse