Explore how to update user account details via the User API.
In this article, we'll look at how to update user data via the User API for different use cases.
Staffbase offers many ways to update a user account's profile fields and avatars. In some use cases, it is not possible to perform bulk updates of the profile fields or avatars for a large number of users via CSV import or SCIM. In such cases, use the User API to simplify your business processes.
Before taking a look at the following use cases, get familiar with the Staffbase user model. Understanding user attribute structure will help you work with the User API.
- You have already generated an API token with administrative access via the Staffbase Studio.
For all the use cases in this article, you need the id
or externalID
of the user to update the user information.
- 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.
To upload a user avatar, do the following:
Step 1: Get the URL to the avatar.
Step 2: Update the avatar of the user.
- Create an image file based on our specifications for avatar images.
- Make a
POST
request to the endpoint/media
to upload the file.
1export AUTH="Basic TOKEN"2 export FILEPATH="C:/Users/Pictures/Avatar.png"34 curl "https://exampleapp.staffbase.com/api/media" \5 -X POST \6 -H "Authorization: $AUTH" \7 -H "Content-Type: multipart/form-data" \8 -F 'file=@$FILEPATH'9 --compressed | json_pp
Learn more about our Media API.
- Get the URL of the uploaded file from the request response.
You can now use this URL to update a user's avatar.
Make a PUT
request to the endpoint /users/{userID}
and in the request body schema, set the avatar parameter as the URL to the avatar.
1 export USERID="5db0221d0a09a219c4ce9218"2 export AUTH="Basic TOKEN"34 curl "https://exampleapp.staffbase.com/api/users/$userID" \5 -X PUT \6 -H "Authorization: $AUTH" \7 -H "Content-Type: application/json" \8 --data-raw '{9 "avatar": {avatarURL}10 }' \11 --compressed | json_pp
You have updated the avatar of a user. To bulk update user avatars, add a function to loop through all users to perform your requests.
You have invited a large number of users to the Staffbase platform and want to update their content language, for example, to Dutch. In this case, you can bulk update the language locale for these users to set their content language to Dutch.
Make a PUT
request to the endpoint /users/{userID}
and in the request body schema, set the locale parameter to nl_NL
, the locale code for Dutch.
1 export USERID="5db0221d0a09a219c4ce9218"2 export AUTH="Basic TOKEN"34 curl "https://exampleapp.staffbase.com/api/users/$userID" \5 -X PUT \6 -H "Authorization: $AUTH" \7 -H "Content-Type: application/json" \8 --data-raw '{9 "config": {10 "locale": "nl_NL"11 },'1213}'14 }' \15 --compressed | json_pp
You have updated the content language setting for a user. To bulk update the content language for multiple users, add a function to loop through all users to perform your requests.