Example:
Basic code uses REST Admin API to create new customer attributes and update existing customer key with identity values in a given environment.
How to use:
- Class wrapper for Admin API, installation instructions in this link: Python Admin API Library Wrapper
- Use the code below, update the following variables:
workspaceName, environmentName, trafficTypeName and customerKey
Admin API key
- The code creates two new attributes (Age and Country), then add values for them to the given customer key.
- Please note that SaveCustomerIdentity() will wipe out any previous stored identities for the customer key, while UpdateCustomerIdentity() will only update the identities in the call.
from splitapiclient.main import get_client
#############################################
workspaceName="Default"
environmentName="Production"
trafficTypeName="employees"
customerKey="dave"
#############################################
client = get_client({'apikey': 'ADMIN API KEY'})
ws = client.workspaces.find(workspaceName)
tp = client.traffic_types.find('user', ws.id)
env = client.environments.find(environmentName, ws.id)
at1 = tp.add_attribute({"id": "attrib90", "displayName": "Age", "description": "age",
"dataType": "STRING", "isSearchable": False, "workspaceId": ws.id})
at2 = tp.add_attribute({"id": "attrib11", "displayName": "Country", "description": "country name",
"dataType": "STRING", "isSearchable": False, "workspaceId": ws.id})
# Adding 50 as age
at = tp.add_identity({'key': customerKey, 'values': {'attrib456': '50'}, 'environmentId': env.id})
# Adding USA as country
at = tp.add_identity({'key': customerKey, 'values': {'attrib11': 'USA'}, 'environmentId': env.id})
Comments
0 comments
Please sign in to leave a comment.