A php library for interacting with AutopilotHQ API http://docs.autopilot.apiary.io/#.
$ composer require picr/php-autopilothq
All interaction occurs in the AutopilotManager
class.
$manager = new AutopilotManager($apiKey);
$manager->getContact($id|$email);
$manager->saveContact(AutopilotContact $contact);
$manager->saveContacts(array $contacts);
$manager->deleteContact($id|$email);
$manager->unsubscribeContact($id|$email);
$manager->subscribeContact($id|$email);
$manager->updateContactEmail($oldEmail, $newEmail);
$manager->getAllLists();
$manager->createList($list);
$manager->getListByName($list);
//TODO: AutopilotHQ hasn't implemented this yet
$manager->deleteList($list);
$manager->getAllContactsInList($list);
$manager->addContactToList($list, $id|$email);
$manager->removeContactFromList($list, $id|$email);
$manager->checkContactInList($list, $id|$email);
$manager->allTriggers();
$manager->addContactToJourney($journey, $id|$email);
$manager->allRestHooks();
$manager->deleteAllRestHooks();
$manager->addRestHook($event, $targetUrl);
$manager->deleteRestHook($hookId);
// magic method
$value = $contact->$name;
// getter
$value = $contact->getFieldValue($name);
// magic method
$contact->$name = $value;
// setter
$contact->setFieldValue($name, $value);
// magic method
unset($contact->$name);
// method
$contact->unsetFieldValue($name);
// magic method
isset($contact->$name);
// method
$contact->issetFieldValue($name);
//NOTE: this only reads cached "lists" array returned for a "contact info" request
$contact->getAllContactLists();
//NOTE: this only reads cached "lists" array returned for a "contact info" request
$contact->hasList($list);
// read array of values and populate properties
// NOTE: automatically formats attributes according to AutopilotHQ's "naming convention" (doesn't really exist)
$contact->fill([
'firstName' => 'John',
'lastName' => 'Smith',
'age' => 42,
]);
// return array ready to be pushed to the API
$user = $contact->toRequest();
// return array of [ property => value ] no matter if custom or defined field
$user = $contact->toArray();
/* [
* 'firstName' => 'John',
* 'lastName' => 'Smith',
* 'age' => 42,
* ]
*/
// json representation of "toArray()"
$user = $contact->jsonSerialze();
$user = json_encode($contact);
MIT