Learn how to populate the user reference input type for profile fields using the User API.
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.
- You have already created an API token with administrative access via the Staffbase Studio.
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.
- Make a
GET
request to the endpoint/users
to list all users.
1 export AUTH="Basic {{Token}}"23 curl -X GET 'https://exampleapp.staffbase.com/api/users' \4 -H 'Authorization: $AUTH' \5 --compressed | json_pp
- Filter the response for the
id
orexternalID
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.
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.