Table of Contents
Description
This is an example of a wrapper NodeJS library for our API functionality, it provide an easy way to interact with Split from within your application.
The NodeJS client is instantiated using an admin API key. For more information on how to generate API key, click here.
Get Started
- Download the NodeJS Library from the following
Link - Create a new folder for your node app, follow command line instructions
npm init
- Create subfolder node_modules and unzip the library file inside it, it should create @splitsoftware/splitio-api folders
- cd to splitio-api folder and run the command below to download dependent libraries
npm update
- Back to the app folder root, open package.json file and add the section below before the last end bracket:
"dependencies": {
"@splitsoftware/splitio-api": "^2.0.0"
}
- Instantiate the wrapper and Create a new Split API client
var SplitAPI = require('@splitsoftware/splitio-api');
var ApiClient = new SplitAPI.client('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
ApiClient.workspaces.list().then(function(rs) {
rs.forEach(function(value){
console.log(value['name']+", "+value['id']+"\n");
});
});
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
ApiClient.environments.list('WORSKPACE ID').then(function(rs) {
rs.forEach(function(value){
console.log(value['name']+"\n");
});
});
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
ApiClient.trafficTypes.list('WORKSPACE ID').then(function(rs) {
rs.forEach(function(value){
console.log(value['name']+"\n");
});
});
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
ApiClient.attributes.list('WORKSPACE ID', 'TRAFFIC TYPE ID').then(function(rs) {
rs.forEach(function(value){
console.log(value);
body=body+value['name']+"\n";
});
});
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
var myAttribute = new SplitAPI.entities.Attribute({
id: 'identifier',
trafficTypeId: 'a_traffic_type_id'
});
ApiClient.attributes.create('WORKSPACE ID', myAttribute).then(function(res) {
// The response would be an Attribute instance, with the data as it's on the BE.
});
delete
Delete an attribute for a traffic type ID.
Params: workspace Id, trafficType Id
ApiClient.attributes.delete('WORKSPACE ID', myAttribute).then(function(res) {
// The response would be a boolean flag
});
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
var myIdentity = new SplitAPI.entities.Identity({
key: 'key',
environmentId: 'environmentId',
trafficTypeId: 'trafficTypeId',
values: {
'attribute_id': 'value'
}
});
ApiClient.identities.save(myIdentity).then(function(res) {
// The response would be an Identity instance, with the data as it's on the BE.
});
save_all
Create or overwrite a single customer ID for a given traffic type and environment.
Params: environment Id, trafficType Id, Idenitiy[]
ApiClient.identities.saveBulk([myIdentity, anotherIdentity]).then(function(res) {
// Do something with the saved identities
});
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
var myIdentity = new SplitAPI.entities.Identity({
key: 'a_key',
environmentId: 'env_id',
trafficTypeId: 'tt_id',
values: {
'email': 'mail@gmail.com'
}
});
ApiClient.identities.update(myIdentity).then(function(res) {
// The response would be an Identity instance, with the data as it's on the BE.
});
delete
Delete a single customer ID for a given traffic type and environment.
Params: environment Id, trafficType Id
ApiClient.identities.delete(trafficTypeId, environmentId, key).then(function(res) {
// The response would be a boolean flag, indicating the result of the operation
});
Comments
0 comments
Please sign in to leave a comment.