Example: Basic code to use Python and Split REST API to delete segment keys on chunks when the segment contains thousands of keys.
How to use:
- Class wrapper for Admin API, installation instructions in this link: Python Admin API Library Wrapper
- Use the code below to update your relevant Split Admin API key, environment, workspace, and segment names.
Note:
- If you only have one workspace, use the Default workspace.
from splitapiclient.main import get_client
#############################################
workspaceName = "Defaults"
environmentName = "Production"
segmentName = "employees"
#############################################
client = get_client({'apikey': 'ADMIN API KEY'})
ws = client.workspaces.find(workspaceName)
env = client.environments.find(environmentName, ws.id)
segDef = client.segment_definitions.find(segmentName, env.id, ws.id)
segKeys = segDef.get_keys()
cnt=0
keys = []
for key in segKeys:
cnt = cnt + 1
if cnt > 90:
final = {"keys": keys, "comment":"removing 1k keys"}
segDef.remove_keys(final)
keys = []
cnt = 0
keys.append(key)
if cnt < 90:
final = {"keys": keys, "comment":"removing 1k keys"}
segDef.remove_keys(final)
Comments
0 comments
Please sign in to leave a comment.