Example:
Basic code to use Python to add new user id (key) in the individual targeted section of given treatment to an existing feature flag
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 also checks if an individual target section already exists for the treatment to change the JSON path accordingly.
How to use:
- Class wrapper for Admin API, installation instructions in this link: Python Admin API Library Wrapper
- Update the code below, update the following variables:
workspaceName, environmentName, splitName, treatmentName and userIds
Admin API Key
from splitapiclient.main import get_client
############################################
workspaceName = "Default"
environmentName = "Production"
splitName = "clients_on"
userIds = ["user1", "user2", "user3"]
treatmentName="off"
############################################
client = get_client({'apikey': 'ADMIN API KEY'})
ws = client.workspaces.find(workspaceName)
env = client.environments.find(environmentName, ws.id)
splitDef = client.split_definitions.find(splitName, env.id, ws.id)
trs = []
for tr in splitDef._treatments:
if tr._name == treatmentName:
tr._keys = userIds
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.