Example:
Basic Code to use Python and Split REST API to individually target segments to treatments for a given array of Split names within a given Workspace/Environment.
How to use:
- Class wrapper for Admin API can be downloaded from the link: Python PyPi library for Split REST Admin API
- Update your relevant Split Admin API Key, Environment Name, Workspace Name, Segment name in code below.
- Update the Splits names and treatment name in the array (splits)
- The tool does not verify if the given segment name is added to the same traffic type and environment.
from splitapiclient.main import get_client
#############################################
workspaceName="Default"
environmentName="Production"
splits=[["clients_on", "off"], ["clients", "off"]]
segmentNames=["coldweather"]
#############################################
ws = client.workspaces.find(workspaceName)
env = client.environments.find(environmentName, ws.id)
splitDef = client.split_definitions.find(splitName, env.id, ws.id)
for splitDef in client.split_definitions.list(env.id, ws.id):
for split in splits:
if splitDef._name == split[0]:
trs = []
for tr in splitDef._treatments:
if tr._name == split[1]:
tr._segments = segmentNames
trs.append(tr.export_dict())
rls = []
for rl in splitDef._rules:
rls.append(rl.export_dict())
drls = []
for drl in splitDef._default_rule:
drls.append(drl.export_dict())
splitDefinition = {"treatments": trs,"defaultTreatment": splitDef._default_treatment, "rules": rls, "defaultRule": drls}
splitDef.update_definition(splitDefinition)
Comments
0 comments
Please sign in to leave a comment.