Example: Basic Code to use Python to add new user id (key) in whitelist section of given treatment to an existing Split
Script will use the REST Admin API to perform the actions. The example will determine the treatment order to use in constructing the patch request payload, it will also check if a whitelist section already exist for the treatment to change the JSON path accordingly.
Environment:
- Python 2.7.15
- requests 2.18.1
How to use:
- Class wrapper for Admin API can be downloaded from the link below:
SplitAPI.py
- Update the code below, update the following variables:
workspaceName, environmentName, splitName, treatmentName and userId
Admin API Key
- The code use two methods, one to add bulk keys to a whitelist section, the other only one key.
import SplitAPI
import json
############################################
workspaceName = "Default"
environmentName = "Production"
splitName = "clients_on"
userId = "john"
userIds = ["one", "tow", "three" ]
treatmentName="off"
############################################
mySplit = SplitAPI.SplitAPI('ADMIN API KEY')
workspaceId = mySplit.GetWorkspaceId(workspaceName)
mySplit.AddWhiteListToSplit(workspaceId, environmentName, splitName, treatmentName, userId)
mySplit.AddBulkWhiteListToSplit(workspaceId, environmentName, splitName, treatmentName, userIds)
Comments
0 comments
Please sign in to leave a comment.