Skip to content

User Profile Update

js.sevestre edited this page Feb 11, 2019 · 18 revisions

User profile update

get user Directory configuration

body = {
    "instanceId": xxx, 
    "lang": "en", # adapt 
    "type": ["user_directory"],
    "excludeType": ["community", "custom", "custom_list", "image_gallery", "menu", "news", "news_list", "page", "post"],
    "action": "CUSTOM_EDIT"}

user_directories = api.get_call(
    "content", "list", body=body, fields="cursor,items(template/components,uid)")

Each user directory has a list of fields define in user_directory.template.components.

Update the user profile

See Auth&Connect for how to build a service.

CUSTOMER_ID = 'XXX'
INSTANCE_ID = 'YYY'

api = ApiClient()

# User directory ID. This ID is available also in the javascript console. You can type: "USER_DIRECTORIES".
# It isn't an object, it's an array of objects. You can compare the objects to retrieve your user directory.
USER_DIRECTORY_ID = 'ZZZ'
USER_TO_UPDATE_EMAIL = 'me@customer.com'

# Get the user we want to update
userToUpdate = api.get_call('user', 'directory', 'get', email=USER_TO_UPDATE_EMAIL, contentId=USER_DIRECTORY_ID)

# To update custom user directory field, we have to update the values stored in the "customProfile" field.
# Check your user user_directory custom fields by looking into the user_directory object.
# The fields are stored in the user_directory.template.components. Components is an array of fields
# To modify them, get the "uid" you want and proceed like so.
customProfileFieldToEdit1 = '1a3227d9-fa9b-4019-abf0-3525334e655f'

userToUpdate['customProfile'][customProfileFieldToEdit1] = '1990-08-15'

# To save a user in a user directory, you must add the user_directory ID in the user params.
userToUpdate['contentId'] = USER_DIRECTORY_ID

response = api.get_call('user', 'directory', 'save', body=userToUpdate)

print response['customProfile']
Clone this wiki locally