Sync Data to User Reference Input Type Using the User API

Learn how to populate the user reference input type for profile fields using the User API.

Employee App
Front Door Intranet

In this article, you will learn how to update the user reference field of a large number of users. For example, their manager field. In that case, you can bulk update the manager profile field for these users using the User API.

Copy the base URL from the API token page in the Staffbase Studio before you begin.

You need to first retrieve the user ID or the identifier of the user’s profile field you want to update.

  1. Make a GET request to the endpoint /users to list all users.
Terminal window
export AUTH="Basic {{Token}}"
curl -X GET 'https://exampleapp.staffbase.com/api/users' \
-H 'Authorization: $AUTH' \
--compressed | json_pp
  1. Filter the response for the id or externalID of the user.

You have the user ID or the identifier of the user’s profile field you want to update.

Make a PUT request to the endpoint /users/{userID} and in the request body schema, set the manager parameter with an identifier or the User ID of the user.

Terminal window
export USERID="5db0221d0a09a219c4ce9218"
export AUTH="Basic TOKEN"
curl "https://exampleapp.staffbase.com/api/users/$userID" \
-X PUT \
-H "Authorization: $AUTH" \
-H "Content-Type: application/json" \
--data-raw '{
"profile": {
"system_manager": "5db0221d0a09a219c4ce9218"
},
}' \
--compressed | json_pp

You have updated the user reference input type profile field of a user. To bulk update this profile field, add a function to loop through all users to perform your requests.