GithubHelp home page GithubHelp logo

treehousetim / activecampaign-api-v3-wrapper Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dhrechanyi/activecampaign-api-v3-wrapper

0.0 1.0 0.0 28 KB

Wrapper for ActiveCampaign API v3, which allows to work with their services, using PHP

PHP 100.00%

activecampaign-api-v3-wrapper's Introduction

ActiveCampaign API v3 Wrapper

Wrapper for ActiveCampaign API v3. Allows to make calls in ActiveCampaign services and work with data, using PHP. Simple and easy to use. Services available so far:

  • Lists
  • Contacts
  • Tags
  • Custom Fields

Official API documentation

https://developers.activecampaign.com/v3/reference

Installation

ActiveCampaign API v3 Wrapper is available on Packagist. Just add this line to your composer.json file in require section

"treehousetim/activecampaign-api-v3-wrapper": "^1.0"

or open terminal window and run

composer require treehousetim/activecampaign-api-v3-wrapper

Usage

Wrapper allows you to chain methods and use a single instance to apply all needed filters and queries.

Setup

<?php

// include required classes
require 'vendor/autoload.php';

use treehousetim\ActiveCampaign\ActiveCampaign;

// using hard coded values
$ac = new ActiveCampaign( 'ACTIVE_CAMPAIGN_URL', 'ACTIVE_CAMPAIGN_KEY');

// using environment variables
$ac = new ActiveCampaign();

Using Environment Variables requires entries in a .env file or in your environment

Get service models

To get access to the active campaign api endpoints, you will need to create a service model first.

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

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

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

// custom fields
$fields = $ac->customFields();

Basic example

To retrieve all lists, call the ->all() method. This method should be always at the very end of your chain sequence:

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

Note that by default the Active Campaign API returns 20 items.

Pagination

https://developers.activecampaign.com/reference/pagination

Pagination allows you to get needed amount of items and make offsets. Note the API limit is 100 items max.

// fetch the first 50 lists
$limit = 50;
$offset = 0;

$paginated_lists = $ac->lists()->paginate( $limit, $offset )->all();

Sorting

https://developers.activecampaign.com/v3/reference#section-ordering You can sort results in needed order. Use ->orderby() method and pass as argument an array, where key is the name of field and value is order (asc or desc).

// get all contacts and sort them by email in asc order and by last name in desc order
$contacts = $ac->contacts()->orderby( ['email' => 'asc', 'lastName' => 'desc'] )->all();

Filtering

https://developers.activecampaign.com/v3/reference#section-filtering You can filter results by multiple parameters. Use ->filter() method and pass an array as argument, where key is parameter name and value is parameter value.

// get contacts where first name is equal to John
$contacts = $ac->contacts()->filter(['firstName' => 'john'])->all();

URL Queries

Additionaly, you can add any parameter to url that will be send to activecampaign endpoint. Use ->query() method and pass as argument an array with parameters key and value

$ac->tags()->query(['foo' => 'bar'])->all();

Get item by ID

To access any item by it's ID, use ->get($id) method.

// get tag with ID == 1
$tag = $ac->tags()->get(1);

Advanced examples

// 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
]);

activecampaign-api-v3-wrapper's People

Contributors

treehousetim avatar dhrechanyi avatar nilsminten avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.