PHP Table of Contents
Description
This is an example of a wrapper PHP library for our API functionality, it provides an easy way to interact with Split from within your application.
The PHP client is instantiated using an admin API key. For more information on how to generate API key, click here.
Get Started
- Download the PHP Library from the following
Link - Alternatively, run the following command to install the library
composer require splitsoftware/split-api-client
- Instantiate the wrapper and create a new Split API client
<?php
require_once 'vendor/autoload.php';
use SplitIO\ApiClient\SplitApiClient;
$client = new SplitApiClient(array('apikey' => 'Admin API Key'));
Workspaces
- Structure
"id": "string", // Server populated identifier
"name": "string", // Display name
- Methods
list
Return list of existing Workspaces in the Organization as workspace object
$workspaces = $client->workspaces()->listAll();
foreach($workspaces as $workspace) {
echo "\n".$ws->getName().", ".$ws->getId();
}
Environments
- Structure
"id": "string", // Server populated identifier
"name": "string", // Display name
"production": "boolean" // Production environment or not
- Methods
list
Return list of existing Environments for given Workspace
Params: Workspace ID
$envs = $client->environments()->listAll("WORKSPACE ID");
foreach($envs as $env) {
echo "\n".$env->getName();
}
TrafficTypes
- Structure
"id": "string", // Server populated identifier
"name": "string", // Display name
"displayAttributeId": "string" // (Optional) Attribute used for display name in UI
- Methods
list
Return list of all existing TestTypes in the organization
$trafficTypes = $client->trafficTypes()->listAll("WORKSPACE ID");
foreach($trafficTypes as $trafficType) {
echo "\n".$trafficType->getName();
}
Attributes
- Structure
"id": "string", // Attribute identifier, same as used in identity value map
"trafficTypeId": "string", // Traffic type this attribute is associated with
"displayName": "string", // (Optional) How the attribute will be displayed in the UI, defaults to the id
"description": "string", // (Optional) A description of the attribute
"dataType": "string", // (Optional) The data type of the attribute used for display formatting, defaults to displaying the raw string. Must be one of: null, "string", "datetime", "number", "set"
"isSearchable": boolean // (Optional) Deprecated, included for backward compatibility
- Methods
list
Return list of all existing Attributes for a given Workspace and TestType Ids
Params: Workspace Id, TestType Id
$attributes = $client->attributes()->listAll("TESTTYPE ID OR NAME", "WORKSPACE ID");
foreach($attributes as $attribute) {
echo "\n".$attribute->getDisplayName();
}
save
Save an attribute for a traffic type ID. The attribute is created if it does not exist and is overwritten completely if it does.
Params: workspace Id, trafficType Id, display name, description, data type, isSearchable
$attr = $client->attributes()->save(array(
'id' =>'1234', // Attribute id
'trafficTypeId' =>'1', // traffic type Id
'displayName' => 'display name 1234', // Attribute display name
'description' => 'description1234', // Attribute description
'dataType' => 'STRING', // Attribute data type
'isSearchable' => false // is the attribute searchable?
), "WORKSPACE ID"
);
// Alternative 2: Using setter methods
<?php
$client->attributes->save($attr); // Where $attr is an instance of SplitIO\ApiClient\Resources\Attribute.
delete
Delete an attribute for a traffic type ID.
Params: workspace Id, trafficType Id
try {
$client->attributes()->delete($trafficTypeId, $attributeId, $workspaceId);
} catch \SplitIO\ApiClient\Util\Exceptions\HTTPResponseException $e {
logger->warn('Attribute not deleted');
}
Customer Identities
- Structure
key: "string", // Key used for getTreatment() calls
trafficTypeId: "string", // Traffic Type Identifier
environmentId: "string", // Environment Identifier
values: { // Attribute Values (key: Attribute Id, value: value)
key: "string",...
- Methods
save
Create or overwrite a single customer ID for a given traffic type and environment.
Params: environment Id, trafficType Id, key, value
$identity = $client->identities()->save(array(
'key' => 'k1', // identity key
'trafficTypeId' => '1', // traffic type id
'environmentId' => '1', // environment id
'values' => array('asd' => 1), // identity values
'organizationId' => 'org1' // organization id
));
// Alternative 2 (passing an Identity instance):
$client->save($identity); // Where $identity is an instance of SPlitIO\ApiClient\Resources\Identity
save_all
Create or overwrite a single customer ID for a given traffic type and environment.
Params: environment Id, trafficType Id, Idenitiy[]
$identities = $client->identities()->saveAll(array(
array(
'trafficTypeId' => '1',
'environmentId' => '1',
'key' => 'key1',
'values' => array('asd' =>'a', 'qwe' => 'b'), // identity 1 array(key => array(attribute => value))
),
array(
'trafficTypeId' => '1',
'environmentId' => '1',
'key' => 'key2',
'values' => array('asd' =>'c', 'qwe' => 'd'), // identity 1 array(key => array(attribute => value))
),
));
// Alternative 2 (passing an array of Identity instances)
$identities = $client->identities()->saveAll(array($i1, $i2)); // Where $i1 and $i2 are instances of SplitIO/ApiClient/Resources/Identity
update
Update a single customer ID for a given traffic type and environment. Any provided attribute values will be overwritten, but existing values will otherwise remain.
Params: environment Id, trafficType Id, key, values
$identity = $client->identities()->update(array(
'key' => 'k1', // identity key
'trafficTypeId' => '1', // traffic type id
'environmentId' => '1', // environment id
'values' => array('asd' => 1), // identity values
'organizationId' => 'org1' // organization id
));
// Alternative 2 (passing an Identity instance):
$client->update($identity); // Where $identity is an instance of SPlitIO\ApiClient\Resources\Identity
delete
Delete a single customer ID for a given traffic type and environment.
Params: environment Id, trafficType Id
try {
// Alternative 1 (passing ids and key)
$client->identities()->delete($trafficTypeId, $environmentId, $key);
// Alternative 2 (pasing an Identity instance)
$client->identities()->deleteByInstance($identity); // Where $identity is an instance of SplitIO\ApiClient\Resources\Identity
} catch \SplitIO\ApiClient\Util\Exceptions\HTTPResponseException $e {
logger->warn('Identity not deleted');
}
Comments
0 comments
Please sign in to leave a comment.