Skip to content

summersab/php-klaviyo

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 

Repository files navigation

Klaviyo PHP SDK + GET and PUT

This is a fork of the official Klaviyo PHP API that also adds in GET and PUT functionality from robwittman/php-klaviyo. The Guzzle requirement of robwittman was removed by borrowing from the Order Desk PHP Client. It provides a minimal-abstraction wrapper for the track, identify, metrics, profiles, lists (v1 and v2), campaigns, and templates APIs all from the same class.

Table of Contents

  1. Metrics
  2. Profiles
  3. Lists
  4. Lists v2
  5. Campaigns
  6. Templates
  7. Track
  8. Identify

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key);
$args = array(
    "page"  => 1,
    "count" => 100
);
$result = $klaviyo->get("metrics", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key);
$args = array(
    "since" => 1400656845,
    "count" => 100,
    "sort"  => "asc"
);
$result = $klaviyo->get("metrics/timeline", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key);
$args = array(
    "since" => 1400656845,
    "count" => 100,
    "sort"  => "asc"
);
$result = $klaviyo->get("metric/{{METRIC_ID}}/timeline", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key);
$args = array(
    "start_date"  => 2015-01-01,
    "end_date"    => 2015-01-31,
    "unit"        => "week",
    "measurement" => '["sum","ItemCount"]',
    "where"       => '[["ItemCount","=",5]]',
//  "by"          => urlencode('Accepts Marketing'),
    "count" => 100
);
$result = $klaviyo->get("metric/{{METRIC_ID}}/export", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key);
$result = $klaviyo->get("person/{{PERSON_ID}}");
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key);
$args = array(
   '$id'                => 'dqQnNW',
   '$email'             => '[email protected]',
   '$first_name'        => 'George',
   '$last_name'         => 'Washington',
   '$phone_number'      => '555-555-5555',
   '$title'             => 'Ex-president',
   '$organization'      => 'U.S. Government',
   '$city'              => 'Mount Vernon',
   '$region'            => 'Virginia',
   '$country'           => 'US',
   '$zip'               => '22121',
   '$image'             => 'http://media.clarkart.edu/Web_medium_images/1955.16.jpg',
   '$timezone'          => 'US/Eastern',
   'favorite_ice_cream' => 'vanilla'
);
$result = $klaviyo->put("person/{{PERSON_ID}}", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key);
$args = array(
    "since" => 1400656845,
    "count" => 100,
    "sort"  => "asc"
);
$result = $klaviyo->get("person/{{PERSON_ID}}/metrics/timeline", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key);
$args = array(
    "since" => 1400656845,
    "count" => 100,
    "sort"  => "asc"
);
$result = $klaviyo->get("person/{{PERSON_ID}}/metric/{{METRIC_ID}}/timeline", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$result = $klaviyo->get("people");
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

DEPRECATED: Please use the Lists API V2.

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key);
$args = array(
    "type"  => "segment",
    "page"  => "1",
    "count" => "100"
);
$result = $klaviyo->get("lists", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

DEPRECATED: Please use the Lists API V2.

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key);
$args = array(
    "name"        => "My New List",
    "list_type"   => "standard"
);
$result = $klaviyo->post("lists", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

DEPRECATED: Please use the Lists API V2.

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key);
$result = $klaviyo->get("list/{{LIST_ID}}");
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

DEPRECATED: Please use the Lists API V2.

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key);
$args = array(
    "name" => "My New List Name"
);
$result = $klaviyo->put("list/{{LIST_ID}}", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

DEPRECATED: Please use the Lists API V2.

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key);
$result = $klaviyo->delete("list/{{LIST_ID}}");
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

DEPRECATED: Please use the Lists API V2.

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key);
$args = array(
    "email" => '["[email protected]","[email protected]"]'
);
$result = $klaviyo->get("list/{{LIST_ID}}/members", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key);
$args = array(
    "email" => '["[email protected]","[email protected]"]'
);
$result = $klaviyo->get("segment/{{SEGMENT_ID}}/members", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

DEPRECATED: Please use the Lists API V2.

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key);
$args = array(
    "email"          => "[email protected]",
    "properties"     => '{ "$first_name" : "George", "Birthday" : "02/22/1732" }',
    "confirm_optin"  => true
);
$result = $klaviyo->post("list/{{LIST_ID}}/members", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

DEPRECATED: Please use the Lists API V2.

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key);
$args = array(
    "batch"          => '[ { "email" : "[email protected]", "properties" : { "$first_name" : "George", "Birthday" : "02/22/1732" } }, { "email" : "[email protected]" } ]',
    "confirm_optin"  => true
);
$result = $klaviyo->post("list/{{LIST_ID}}/members/batch", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

DEPRECATED: Please use the Lists API V2.

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key);
$args = array(
    "batch" => '[ { "email" : "[email protected]" }, { "email" : "[email protected]" } ]'
);
$result = $klaviyo->delete("list/{{LIST_ID}}/members/batch", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

DEPRECATED: Please use the Lists API V2.

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key);
$args = array(
    "email"       => "[email protected]",
    "timestamp"   => 1400656845
);
$result = $klaviyo->post("list/{{LIST_ID}}/members/exclude", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

DEPRECATED: Please use the Lists API V2.

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key);
$args = array(
    "reason"   => "unsubscribe",
    "sort"     => "desc"
);
$result = $klaviyo->get("list/{{LIST_ID}}/exclusions", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key);
$args = array(
    "reason"   => "unsubscribe",
    "sort"     => "desc"
);
$result = $klaviyo->get("people/exclusions", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key);
$args = array(
    "email"       => "[email protected]",
    "timestamp"   => 1400656845
);
$result = $klaviyo->post("people/exclusions", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key, null);
$args = array(
    "version"   => 2
);
$result = $klaviyo->post("segment/{{SEGMENT_ID}}/get-members", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key, null);
$args = array(
    "version"   => 2
);
$result = $klaviyo->post("list/{{LIST_ID}}/get-members", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key, null);
$args = array(
    "version"   => 2
);
$result = $klaviyo->post("list/{{LIST_ID}}/get-list-subscriptions", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key, null);
$args = array(
    "version"   => 2
);
$result = $klaviyo->get("lists", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key, null);
$args = array(
    "version"   => 2
);
$result = $klaviyo->post("people/exclusions", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key, null);
$args = array(
    "list_name" => "my new list name",
    "version"   => 2
);
$result = $klaviyo->post("lists", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key, null);
$args = array(
    "version"   => 2
);
$result = $klaviyo->get("lists", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key, null);
$args = array(
    "version"   => 2
);
$result = $klaviyo->get("list/{{LIST_ID}}", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key, null);
$args = array(
    "list_name" => "my new list name",
    "version"   => 2
);
$result = $klaviyo->put("list/{{LIST_ID}}", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key, null);
$args = array(
    "version"   => 2
);
$result = $klaviyo->delete("list/{{LIST_ID}}", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key, null);
$args = array(
    "profiles" => '[ { "email": "[email protected]", "example_property": "valueA" }, { "email": "[email protected]", "example_property": "valueB" } ]',
    "version"   => 2
);
$result = $klaviyo->post("list/{{LIST_ID}}/subscribe", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key, null);
$args = array(
    "emails" => '["[email protected]", "[email protected]"]',
    "version"   => 2
);
$result = $klaviyo->get("list/{{LIST_ID}}/subscribe", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key, null);
$args = array(
    "emails" => '["[email protected]", "[email protected]"]',
    "version"   => 2
);
$result = $klaviyo->delete("list/{{LIST_ID}}/subscribe", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key, null);
$args = array(
    "profiles" => '[ { "email": "[email protected]", "example_property": "valueA" }, { "email": "[email protected]", "example_property": "valueB" } ]',
    "version"   => 2
);
$result = $klaviyo->post("list/{{LIST_ID}}/members", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key, null);
$args = array(
    "emails" => '["[email protected]", "[email protected]"]',
    "version"   => 2
);
$result = $klaviyo->delete("list/{{LIST_ID}}/members", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key, null);
$args = array(
    "marker" => 123456,
    "version"   => 2
);
$result = $klaviyo->get("list/{{LIST_ID}}/exclusions/all", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key, null);
$result = array(
    "marker" => 1
);

while (array_key_exists("marker", $result)) {
    $args = array(
        "marker" => $result["marker"],
        "version"   => 2
    );
    $result = $klaviyo->get("list/{{LIST_ID or SEGMENT_ID}}/members/all", $args);
    echo "<pre>" . print_r($result, 1) . "</pre>";
}
?>

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key, null);
$args = array(
    "emails" => '["[email protected]", "[email protected]"]',
    "version"   => 2
);
$result = $klaviyo->get("list/{{LIST_ID}}/members", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key);
$args = array(
    "page"  => 1,
    "count" => 100
);
$result = $klaviyo->get("campaigns", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key);
$args = array(
    "list_id"              => "erRoOX",
    "template_id"          => "gtTqQZ",
    "from_email"           => "[email protected]",
    "from_name"            => "George Washington",
    "subject"              => "Company Monthly Newsletter",
    "name"                 => "Campaign Name",
    "use_smart_sending"    => true,
    "add_google_analytics" => true
);
$result = $klaviyo->post("campaigns", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key);
$result = $klaviyo->get("campaign/{{CAMPAIGN_ID}}");
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key);
$args = array(
    "list_id"              => "erRoOX",
    "template_id"          => "gtTqQZ",
    "from_email"           => "[email protected]",
    "from_name"            => "George Washington",
    "subject"              => "Company Monthly Newsletter",
    "name"                 => "Campaign Name",
    "use_smart_sending"    => true,
    "add_google_analytics" => true
);
$result = $klaviyo->put("campaign/{{CAMPAIGN_ID}}", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key);
$result = $klaviyo->post("campaign/{{CAMPAIGN_ID}}/send");
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key);
$args = array(
    "send_time"   => "2013-06-14 00:00:00"
);
$result = $klaviyo->post("campaign/{{CAMPAIGN_ID}}/schedule", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key);
$result = $klaviyo->post("campaign/{{CAMPAIGN_ID}}/cancel", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key);
$args = array(
    "name"     => "Cloned Campaign",
    "list_id"  => "erRoOX"
);
$result = $klaviyo->post("campaign/{{CAMPAIGN_ID}}/clone", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key);
$args = array(
    "count"    => 25000,
    "sort"     => "desc",
    "offset"   => "Z2VvcmdlLndhc2hpbmd0b25AZXhhbXBsZS5jb20=",
);
$result = $klaviyo->get("campaign/{{CAMPAIGN_ID}}/recipients", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key);
$result = $klaviyo->get("email-templates", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key);
$args = array(
    "name" => "My New Template",
    "html" => "<html><body><p>This is an email for {{ email }}.</p></body></html>"
);
$result = $klaviyo->post("email-templates", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key);
$args = array(
    "name" => "My New Template",
    "html" => "<html><body><p>This is an email for {{ email }}.</p></body></html>"
);
$result = $klaviyo->put("email-template/{{TEMPLATE_ID}}", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key);
$result = $klaviyo->delete("email-template/{{TEMPLATE_ID}}", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key);
$args = array(
    "name" => "My Cloned Template"
);
$result = $klaviyo->post("email-template/{{TEMPLATE_ID}}/clone", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key);
$args = array(
    "context" => '{ "name" : "George Washington", "notifcation_count" : 10 }',
);
$result = $klaviyo->post("email-template/{{TEMPLATE_ID}}/render", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

<?php
include "Klaviyo.php";
$api_key = "pk_123456789abcdef123456789abcdef12";
$klaviyo = new Klaviyo($api_key);
$args = array(
    "from_email" => "[email protected]",
    "from_name"  => "George Washington",
    "subject"    => "Company Monthly Newsletter",
    "context"    => '{ "name" : "George Washington", "notifcation_count" : 10 }'
);
$result = $klaviyo->post("email-template/{{TEMPLATE_ID}}/send", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

<?php
include "Klaviyo.php";
$token = "ABC123";
$klaviyo = new Klaviyo(null, $token);
$event = "Elected President";
$customer_properties = array(
    '$email' => "[email protected]"
);
$properties = array(
    "PreviouslyVicePresident" => true,
    "YearElected"             => 1801,
    "VicePresidents"          => ["Aaron Burr", "George Clinton"]
);
$time = 1537057291;
$result = $klaviyo->tracker($event, $customer_properties, $properties, $time);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

However, since a GET request is being performed in the class, the following implementation is also supported:

<?php
include "Klaviyo.php";
$token = "ABC123";
$klaviyo = new Klaviyo(null, $token);
$args = array(
    "event" => "Elected President",
    "customer_properties" => array(
        '$email' => "[email protected]"
    ),
    "properties" => array(
        "PreviouslyVicePresident" => true,
        "YearElected"             => 1801,
        "VicePresidents"          => ["Aaron Burr", "George Clinton"],
        '$event_id'               => 10001234,
        '$value'                  => 11.25
    ),
    "time" => 1537057291
);
$result = $klaviyo->get("track", $args);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

<?php
include "Klaviyo.php";
$token = "ABC123";
$klaviyo = new Klaviyo(null, $token);
$properties = array(
    '$id'           => 'dqQnNW',
    '$email'        => '[email protected]',
    '$first_name'   => 'George',
    '$last_name'    => 'Washington',
    '$phone_number' => '555-555-5555',
    '$title'        => 'Ex-president',
    '$organization' => 'U.S. Government',
    '$city'         => 'Mount Vernon',
    '$region'       => 'Virginia',
    '$country'      => 'US',
    '$zip'          => '22121',
    '$image'        => 'http://media.clarkart.edu/Web_medium_images/1955.16.jpg',
    "Plan"          => "Premium",
    "SignUpDate"    => "2016-05-01 10:10:00"
);
$result = $klaviyo->identify($properties);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

However, since a GET request is being performed in the class, the following implementation is also supported:

<?php
include "Klaviyo.php";
$token = "ABC123";
$klaviyo = new Klaviyo(null, $token);
$properties = array(
    '$id'           => 'dqQnNW',
    '$email'        => '[email protected]',
    '$first_name'   => 'George',
    '$last_name'    => 'Washington',
    '$phone_number' => '555-555-5555',
    '$title'        => 'Ex-president',
    '$organization' => 'U.S. Government',
    '$city'         => 'Mount Vernon',
    '$region'       => 'Virginia',
    '$country'      => 'US',
    '$zip'          => '22121',
    '$image'        => 'http://media.clarkart.edu/Web_medium_images/1955.16.jpg',
    "Plan"          => "Premium",
    "SignUpDate"    => "2016-05-01 10:10:00"
);
$result = $klaviyo->get("identify", $properties);
echo "<pre>" . print_r($result, 1) . "</pre>";
?>

About

PHP wrapper for the Klaviyo API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%