Our RESTful API doesn't only enable you to access your company's data, it can also be used to manage users via different endpoints:
- Retrieve all users records
- Create users
- Search for users
- Retrieve a single user record
- Delete users
- Update users
In this article, we'll go over the "update user" endpoint and provide some guidance on how you can bulk update user email addresses.
Update Users
This endpoint enables you to update a user with the given data.
NOTE: Tags will be replaced
Fields that can be updated:
- Enabled: true/false
- Role
- Team
- Tags
- PreferredDevLanguages
Tip: You can disable the change of email notification sent to users by setting the skipNotifyIfSso field to false
How to bulk update users' emails
We created a script that can be used to update user(s) email addresses.
- Get the API Key
- Save the script below into a file named update_email_addresses.sh
- Execute the following command line in a posix shell: (replace the xxxxxxx with the API key)
SCW_API_KEY=xxxxxxx. ./update_email_addresses.sh 2>log.txt
Things to note:
- We highly recommend you delete the command from the shell history when done to best protect the API key.
- Depending on the number of users you want to update, it might take a few minutes to update all users
#!/bin/sh set -e [ -z "${SCW_API_KEY:-}" ] && echo "Usage SCW_API_KEY=xxx $0 [--skipNotifyIfSso] 2>log.txt" && exit 1 api_key_header="X-API-Key: ${SCW_API_KEY}" api_host="portal-api" # api_host="portal-api.eu" api_url="https://${api_host}.securecodewarrior.com/api/v2/users" skip_notify_if_sso=false [ "--skipNotifyIfSso" = "$1" ] && skip_notify_if_sso=true updateUserEmail() { old=$1 new=$2 output=$( echo "${old} -> ${new}" curl -s -X PATCH -H "Accept: application/json" -H "${api_key_header}" -H "Content-Type: application/json" \ -d "{ \"email\": \"${new}\"}" \ "${api_url}/${old}?skipNotifyIfSso=${skip_notify_if_sso}&idtype=email" echo ) echo "${output}" >&2 } # Examples #Basic usage #updateUserEmail "foo@bar.com" "foo@baz.com" # changes domain part #updateUserEmail "cat@bar.com" "dog@bar.com" # changes name part # Sequential updates. This waits for completion of each update before posting the next. #updateUserEmail "alice@bar.com" "alice@baz.com" #updateUserEmail "bob@bar.com" "bob@baz.com" #updateUserEmail "charlie@bar.com" "charlie@baz.com" # Parallel updates: use trailing ampersand to run multiple updates at the same time. These should broken up into batches # to avoid rate limiting mechanisms #updateUserEmail "alice@bar.com" "alice@baz.com" & #updateUserEmail "bob@bar.com" "bob@baz.com" & #updateUserEmail "charlie@bar.com" "charlie@baz.com" & #updateUserEmail "ella@bar.com" "ella@baz.com" & # wait for above background jobs running in parallel to finish #wait #updateUserEmail "frank@bar.com" "frank@baz.com" & #updateUserEmail "george@bar.com" "george@baz.com" & #updateUserEmail "hugh@bar.com" "hugh@baz.com" & #updateUserEmail "ivan@bar.com" "ivan@baz.com" & #updateUserEmail "joe@bar.com" "joe@baz.com" & # wait for above background jobs running in parallel to finish #wait
Comments
0 comments
Please sign in to leave a comment.