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.

Prerequisite

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

Get the id or externalID of the user

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.
1 export AUTH="Basic {{Token}}"
2
3 curl -X GET 'https://exampleapp.staffbase.com/api/users' \
4 -H 'Authorization: $AUTH' \
5 --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.

Update profile field with user reference input type using the User API

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.

1 export USERID="5db0221d0a09a219c4ce9218"
2 export AUTH="Basic TOKEN"
3 curl "https://exampleapp.staffbase.com/api/users/$userID" \
4 -X PUT \
5 -H "Authorization: $AUTH" \
6 -H "Content-Type: application/json" \
7 --data-raw '{
8 "profile": {
9 "system_manager": "5db0221d0a09a219c4ce9218"
10 },
11 }' \
12 --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.