Azalead Rest API

Get your target account marketing engagement

30 views May 12, 2017 May 12, 2017 developer 0

This tutorial explains how to get marketing engagements for your target accounts. Website visits, ads clicked and emails opened represent account marketing engagements also known as activities.

Step 1 - Create your object classes

First of all you need to create several classes to define the objects you will manipulate. For this use case you will use accounts and activities.

An account is a company with activities. Activities are marketing engagements such as website visits, ads clicked and emails opened.

Account

<?php
/**
*
* An account is a company with activities and labels
*
**/
class Account
{
  private $idAccount;
  private $idNational;
  private $name;
  private $naceCode;
  private $sizeCategory;
  private $employeeCount;
  private $industry;
  private $website;
  private $city;
  private $countryCode;
  private $zipCode;
  private $lastActivityType;
  private $lastActivityDate;
  private $activities;
  private $labels;

  public function setIdAccount($idAccount) {
    $this->idAccount = $idAccount;
  }

  public function getIdAccount() {
    return $this->idAccount;
  }

  public function setIdNational($idNational) {
    $this->idNational = $idNational;
  }

  public function getIdNational() {
    return $this->idNational;
  }

  public function setName($name) {
    $this->name = $name;
  }

  public function getName() {
    return $this->name;
  }

  public function setNaceCode($naceCode) {
    $this->naceCode = $naceCode;
  }

  public function getNaceCode() {
    return $this->naceCode;
  }

  public function setSizeCategory($sizeCategory) {
    $this->sizeCategory = $sizeCategory;
  }

  public function getSizeCategory() {
    return $this->sizeCategory;
  }

  public function setEmployeeCount($employeeCount) {
    $this->employeeCount = $employeeCount;
  }

  public function getEmployeeCount() {
    return $this->employeeCount;
  }

  public function setIndustry($industry) {
    $this->industry = $industry;
  }

  public function getIndustry() {
    return $this->industry;
  }

  public function setWebsite($website) {
    $this->website = $website;
  }

  public function getWebsite() {
    return $this->website;
  }

  public function setCity($city) {
    $this->city = $city;
  }

  public function getCity() {
    return $this->city;
  }

  public function setCountryCode($countryCode) {
    $this->countryCode = $countryCode;
  }

  public function getCountryCode() {
    return $this->countryCode;
  }

  public function setZipCode($zipCode) {
    $this->zipCode = $zipCode;
  }

  public function getZipCode() {
    return $this->zipCode;
  }

  public function setLastActivityType($lastActivityType) {
    $this->lastActivityType = $lastActivityType;
  }

  public function getLastActivityType() {
    return $this->lastActivityType;
  }

  public function setLastActivityDate($lastActivityDate) {
    $this->lastActivityDate = $lastActivityDate;
  }

  public function getLastActivityDate() {
    return $this->lastActivityDate;
  }

  public function setActivities($activities) {
    $this->activities = $activities;
  }

  public function getActivities() {
    return $this->activities;
  }

  public function setLabels($labels) {
    $this->labels = $labels;
  }

  public function getLabels() {
    return $this->labels;
  }
}
?>

Activity

<?php
/**
* An account has activities : website visits, ad clicked, email opened
**/
class Activity
{
  private $idActivity;
  private $activityType;
  private $activityDate;
  private $visitedPages;
  private $referer;
  private $emailOpeners;
  private $campaignName;

  public function setIdActivity($idActivity) {
    $this->idActivity = $idActivity;
  }

  public function getIdActivity() {
    return $this->idActivity;
  }

  public function setActivityType($activityType) {
    $this->activityType = $activityType;
  }

  public function getActivityType() {
    return $this->activityType;
  }

  public function setActivityDate($activityDate) {
    $this->activityDate = $activityDate;
  }

  public function getActivityDate() {
    return $this->activityDate;
  }

  public function setVisitedPages($visitedPages) {
    $this->visitedPages = $visitedPages;
  }

  public function getVisitedPages() {
    return $this->visitedPages;
  }

  public function setReferer($referer) {
    $this->referer = $referer;
  }

  public function getReferer() {
    return $this->referer;
  }

  public function setEmailOpeners($emailOpeners) {
    $this->emailOpeners = $emailOpeners;
  }

  public function getEmailOpeners() {
    return $this->emailOpeners;
  }

  public function setCampaignName($campaignName) {
    $this->campaignName = $campaignName;
  }

  public function getCampaignName() {
    return $this->campaignName;
  }
}
?>

Step 2 - Get your target account list

To get your target account list you need to request the /account endpoint and ask for target accounts.

/account endpoint request

<?php
/**
  *  request api for target accounts
  **/
  public function requestTargetAccounts($token, $page, $size) {
    $ch = curl_init('https://api.azalead.com/latest/account?page='. $page .'&size='. $size .'&target=true');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'X-Auth-Token:Bearer '.$token)
    );

    $apiResults = requestAPI($ch);
    return $apiResults;
  }
?>

Step 3 - Get each account activities

Now for each account your interested in request REST API for its activities.

/account/:id/activity endpoint request

<?php
  /**
  *  request api for account's activities
  **/
  public function requestAccountActivities($token, $account) {
    $ch = curl_init('https://api.azalead.com/latest/account/'. $account->getIdAccount().'/activity');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'X-Auth-Token:Bearer '.$token)
    );

    $apiResults = requestAPI($ch);
    return $apiResults;
  }
?>

Download complete tutorial code example

Was this helpful?