Update Users With the User API

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.

Prerequisite

  • You have already generated an API token with administrative access via the Staffbase Studio.
If your application is hosted on the German Hosting Infrastructure, you need to use a different base URI from the one used in the request examples.

Get the id or externalID of the User

For all the use cases in this article, you need the id or externalID of the user to update the user information.

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

Bulk Update Avatars

To upload a user avatar, do the following:

Step 1: Get the URL to the avatar.
Step 2: Update the avatar of the user.

Step 1: Get the URL to the Avatar

You can skip this step if you already have the URL to the avatar.
  1. Create an image file based on our specifications for avatar images.
  2. Make a POST request to the endpoint /media to upload the file.
1export AUTH="Basic TOKEN"
2 export FILEPATH="C:/Users/Pictures/Avatar.png"
3
4 curl "https://backend.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.

  1. Get the URL of the uploaded file from the request response.
    You can now use this URL to update a user's avatar.

Step 2: Update the 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"
3
4 curl "https://backend.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.

Bulk Update Content Language

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.

Learn more about our languages and locale codes.

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"
3
4 curl "https://backend.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 },'
12
13}'
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.