Managing Users

The TIS Training API provides a few endpoints for managing users programatically. Let's start with creating a user.

First, lets set an email to use for the new user:

TiSUserEmail=[email protected]

Choose an email you have access to, even if you plan on deleting the user later.

Let's create the new user with curl:

🟢POST users
curl https://training.tapintosafety.com.au/api/v2/users \
    -H "Authorization: Bearer $APIKey"                  \
    -H "Content-Type: application/json"                 \
    -d '{ "email": "$TiSUserEmail",                     \
          "firstName": "Allice",                        \
          "lastName": "Smith" }

Now we can see Alice when we ask for a list of users in the organisation.

🔵GET users
curl https://training.tapintosafety.com.au/api/v2/users \
    -H "Authorization: Bearer $APIKey"

Oops! We seem to have misspelt Alice's first name. Let's fix that with our next endpoint.

🟠PUT users
curl https://training.tapintosafety.com.au/api/v2/users \
    -X PUT                                              \
    -H "Authorization: Bearer $APIKey"                  \
    -H "Content-Type: application/json"                 \
    -d '{ "userIdentifier": "$TiSUserEmail",            \
          "email": "[email protected]",            \
          "firstName": "Alice",                         \
          "lastName": "Smith" }

You might have noticed that we haven't set a password for Alice yet. That's because this time we're going to generate a link to login automatically.

🟢POST login
curl "https://training.tapintosafety.com.au/api/v2/login?userIdentifier=$TiSUserEmail"             \
    -X POST                               \
    -H "Authorization: Bearer $APIKey"    \
    -H "Content-Length: 0"

This call should just return a link that you can go to in any browser that will automatically log you into the account specified. Make sure you use the link as soon as it's generated, as it will expire quickly.

So maybe we've decided that Alice needs a password to log in after all. No problem, this brings us to the last endpoint we'll be covering here.

🟢POST users/password
curl "https://training.tapintosafety.com.au/api/v2/users/Password?userIdentifier=$TiSUserEmail"             \
    -H "Authorization: Bearer $APIKey"    \
    -H "Content-Type: application/json"   \
    -d '{ "password": "ExamplePass1" }'

With that, Alice will be able to log in with the new password.

Last updated