Example:
Basic code to use Python and Split REST API to copy segment ids to another segment.
How to use:
- Class wrapper for Admin API, installation instructions in this link: Python Admin API Library Wrapper
- Update your relevant Split Admin API key, environment, workspace and source and target segments in the code below.
Note:
- If you only have one workspace, use the Default workspace.
from splitapiclient.main import get_client
#############################################
sourceSegmentName="admin_api_test"
sourceWorkspaceName="Default"
sourceEnvironmentName="Production"
targetSegmentName = "myaccounts"
targetWorkspaceName = "Default"
targetEnvironmentName = "Production"
#############################################
client = get_client({'apikey': 'ADMIN API KEY'})
sourceWs = client.workspaces.find(sourceWorkspaceName)
sourceEnv = client.environments.find(sourceEnvironmentName, sourceWs.id)
sourceSegmentDef = client.segment_definitions.find(sourceSegmentName, sourceEnv.id, sourceWs.id)
targetWs = client.workspaces.find(targetWorkspaceName)
targetEnv = client.environments.find(targetEnvironmentName, targetWs.id)
targetSegmentDef = client.segment_definitions.find(targetSegmentName, sourceEnv.id, sourceWs.id)
keys = sourceSegmentDef.get_keys()
targetSegmentDef.import_keys_from_json("false", {"keys":keys,"comment":"copy keys from segment"})
Comments
0 comments
Please sign in to leave a comment.