Skip to content

User Profile Update

js.sevestre edited this page Nov 4, 2019 · 18 revisions

User profile update

Profile fields are defined in a User Directory and populate through the user customProfile

Get user Directory configuration

If you have the user directory module id use a content/get call with this id.

Else, get a list of user directory modules on an instance.

# prepare the request parameters
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"}

# get user directory modules list
user_directories = api.get_call(
    "content", "list", body=body, fields="cursor,items(template/components, uid)")
# nb: the fields parameter ask the api to return only the requested fields in the response,
# the returned content could not be used for a save.

The ̀user_directories will be a list of user directory module.

Each user directory module has a list of custom profile fields define in template.components and an uuid.

# example, this user directory module define 2 fields:
# - "Title"
# - "Phone Number"
{
    "title": {
        "en": "Users Directory"
    },
    "id": "6486401110769664",
    "uid": "6486401110769664",
    "instance": "6288388086038528",
    "customer": "4664706704080896",
    "isDefaultUserDirectory": false,
    "type": "user_directory",
    "status": "LIVE",
    "slug": {
        "en": "users-directory"
    },
    "template": {
        "components": [
            {
                "uuid": "be3363f3-4df8-4a93-b27c-9c8c69258801",
                "title": {
                    "en": "Title"
                },
                "type": "inputText",
                "properties": {
                    "index": 0,
                    "isBound": true,
                    "boundMap": {
                        "text": "organizations/title",
                        "name": "API_PROFILE_FIELD_TITLE"
                    },
                    "icon": "bank"
                },
                "status": "LIVE",
            },
            {
                "uuid": "b72127e4-867a-4aba-a843-70c11dc599ef",
                "title": {
                    "fr": "Phone Number"
                },
                "type": "inputText",
                "properties": {
                    "editFeeds": [],
                    "availableValues": [
                        {}
                    ],
                    "icon": "account"
                },
                "status": "LIVE",
            }
        ],
        "heritable": false,
        "createdAt": "2018-04-12T07:43:23.624150",
        "uid": ""
    }
}

Update the user profile

To update the user profile:

  • get the user details for the corresponding user directory
  • update or add value for the custom fields defined by the user directory module.
  • save
CUSTOMER_ID = 'XXX'
INSTANCE_ID = 'YYY'

api_client = ApiClient()

USER_DIRECTORY_MODULE_ID = '6486401110769664'
USER_TO_UPDATE_EMAIL = 'me@customer.com'

# get user details corresponding to a user directory module
userToUpdate = api_client.get_call('user', 'directory', 'get', email=USER_TO_UPDATE_EMAIL, contentId=USER_DIRECTORY_MODULE_ID)

# Update the value of "Title" (get uid from module definition).
field1uid = 'be3363f3-4df8-4a93-b27c-9c8c69258801'
userToUpdate['customProfile'][field1uid] = 'Support Leader'

# Update the value of "Title" (get uid from module definition).
field2uid = 'b72127e4-867a-4aba-a843-70c11dc599ef'
userToUpdate['customProfile'][field2uid] = '00 11 22 33 44 55 66'

# /!\ To save a user in a user directory, you must add the user_directory ID in the user object.
userToUpdate['contentId'] = USER_DIRECTORY_MODULE_ID

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

Warning:

  • if the field is defined with a bound value (ex for the "Title" above: 'organizations/title' ) the Title value will be store on the user under apiProfile.organization.title
  • else, the value will be store under customProfile.{fielduid}.
# example: the response of the previous call

{ 
    [...]
    "email": "me@customer.com",
    "customProfile" : {
        "b72127e4-867a-4aba-a843-70c11dc599ef": "00 11 22 33 44 55 66"
    }
    [...],
    "apiProfile": {
        "organization": {
            "title": "Support Leader"
        }
    }
}
Clone this wiki locally