Example:
Basic code to use Python to add new targeting rules to an existing feature flag.
Script will use the REST Admin API to perform the actions. The example contain two targeting rules added.
How to use:
- Class wrapper for Admin API, installation instructions in this link: Python Admin API Library Wrapper
- Update the following variables in the code below:
workspaceName, environmentName and splitName
Admin API key
from splitapiclient.main import get_client
############################################
workspaceName = "Default"
environmentName = "Production"
splitName = "clients_on"
############################################
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:
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())
rls.append({"buckets": [{"treatment": "on","size": 100}],"condition": {"matchers": [{"attribute":"userGroup", "type": "MATCHES_STRING","string": "employees"}], "combiner": "AND"}})
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.