Optimizely REST API SDK Wrapper

2.0.3 2017-10-24 23:02 UTC


Packagist Travis

Optimizely X token generator

PHP Wrapper to interact with the Optimizely X API.


composer require widerfunnel/optimizely-x-sdk


Simply create an Optimizely object, with a valid OAuth Token in the constructor:

$optimizely = Optimizely::create($token);

If you wish to use the token based authentication, simply pass true as a second argument:

$optimizely = Optimizely::create($token, true);

List projects


Read a project


Create a project

    'name' => 'My new project'

Update a project

    'name' => 'My new name'

Delete a project

** Not supported by Optimizely X Rest API **

Activate a project (note: not functional, waiting on optimizely X api fix)


Archive a project (note: not functional, waiting on optimizely X api fix)



List Campaigns


Find Campaign


Create Campaign

    'Landing Page Optimization',
    ["status" => "not_started"]

Update a Campaign

    'name' => 'this is my new campaign'


List experiments in project

    'per_page' => <integer>,
    'page' => <integer>,
    'include_classic' => <boolean>
] <optional>);

Find experiment


Create an experiment

    'my test',
            "name" => "control",
            "weight" => 5000
            "name" => "varA",
            "weight" => 5000
            "aggregator" => "unique",
            "event_id" => 0,
            "field" => "revenue"
    ['status' => 'not started']

Update an experiment

$optimizely->experiment($experimentId)->update(['name' => 'newsite.com']);

Delete an experiment


Archive an experiment



Change Variations

        "name" => "control",
        "weight" => 2500
        "name" => "varA",
        "weight" => 2500
        "name" => "varB",
        "weight" => 2500
        "name" => "varF",
        "weight" => 2500


List audiences


Find an audience


Create an audience

    'My second audience',
    '[\"and\", {\"type\": \"language\", \"value\": \"es\"}, {\"type\": \"location\", \"value\": \"US-CA-SANFRANCISCO\"}]',
    ["description" => 'People that speak spanish in San Fran']

Update an audience

    'name' => 'My new name'

Delete an audience

** Not supported by Optimizely X Rest API **


List Pages


Find a Page


Create a page

$optimizely->project($projectId)->pages()->create($name, $edit_url, [
    'category' => 'article'

Update a page

$optimizely->page($pageId)->update(['name' => 'my updated name']);

Delete a page



List Events


Find Event


In Page Events

Create In-page Event

    'my sign up goal',
    ['selector' => '.sign-up-btn'],
    ['category' => 'sign_up']

Update In-Page Event

    'name' => 'my new page event name'

Delete In-Page Event


Custom Event

Create Custom Event

    'event_type' => 'custom',
    'name' => 'my custom event',
    'key' => 'my_event_key'

Update Custom Event

    'name' => 'my new custom event name'

Delete Custom Event



List Attributes


Find Attribute


Create Attribute

    'my new attribute',
    ['description' => 'this is an attribute']

Update Attribute

$optimizely->attribute($attributeId)->update(['name' => 'this is my updated attribute']);

Delete Attribute



Fetch the results of an experiment


Fetch the results of an campaign