User Management with the CLI

Listing Users

To list users with the CLI, use the users list command. Make sure to specify the fields you’re interested in.

$ ttn-lw-cli users list --name --state --admin

Output:

[{
  "ids": {
    "user_id": "new-user"
  },
  "created_at": "2019-12-19T09:10:31.426Z",
  "updated_at": "2019-12-19T09:10:40.527Z",
  "name": "New User"
}, {
  "ids": {
    "user_id": "admin"
  },
  "created_at": "2019-12-18T14:54:12.723Z",
  "updated_at": "2019-12-18T14:54:12.723Z",
  "state": "STATE_APPROVED",
  "admin": true
}]

TIP: Use the pagination flags --limit and --page when there are many users.

Searching for Users

To search for users with the CLI, use the users search command. Make sure to specify the fields you’re interested in. We’ll search for users with IDs that contain “new”:

$ ttn-lw-cli users search --id-contains new --name

Output:

[{
  "ids": {
    "user_id": "new-user"
  },
  "created_at": "2019-12-19T09:10:31.426Z",
  "updated_at": "2019-12-19T09:10:40.527Z",
  "name": "New User"
}]

TIP: Use the pagination flags --limit and --page when there are many users.

Creating Users

Network Administrators can create user accounts as follows:

$ ttn-lw-cli users create colleague \
  --name "My Colleague" \
  --primary-email-address [email protected]

Output:

Please enter password:***************
Please confirm password:***************
{
  "ids": {
    "user_id": "colleague"
  },
  "created_at": "2019-12-19T10:54:53.677Z",
  "updated_at": "2019-12-19T10:54:53.677Z",
  "name": "My Colleague",
  "contact_info": [
    {
      "contact_method": "CONTACT_METHOD_EMAIL",
      "value": "[email protected]"
    }
  ],
  "primary_email_address": "[email protected]",
  "password_updated_at": "2019-12-19T10:54:53.674Z",
  "state": "STATE_APPROVED"
}

Inviting Users

You can create invitations for users to join the network with the users invitations create command:

$ ttn-lw-cli users invitations create [email protected]

After you do this, you’ll be able to list the invitations you’ve sent:

% ttn-lw-cli users invitations list

Output:

[{
  "email": "[email protected]",
  "token": "MW7INQWYOE46GLP3AEFQEHR5XIKRYPSRAXFF3CUCLIQPPQ3BNBLQ",
  "expires_at": "2019-12-26T11:41:29.485Z",
  "created_at": "2019-12-19T11:41:29.486Z",
  "updated_at": "2019-12-19T11:41:29.486Z"
}]

And delete an invitation if you want to revoke it:

$ ttn-lw-cli users invitations delete [email protected]

Updating Users

To update users with the CLI, use the users update command. The following command updates the state of user new-user to “approved” and makes them admin of the network:

$ ttn-lw-cli users update new-user --state APPROVED --admin true

Output:

{
  "ids": {
    "user_id": "new-user"
  },
  "created_at": "2019-12-19T09:10:31.426Z",
  "updated_at": "2019-12-19T11:44:39.609Z",
  "state": "STATE_APPROVED",
  "admin": true
}

Deleting Users

To delete a user, use the users delete command.

NOTE: When deleting users, their user IDs stay reserved in the system, it is not possible to create a new user with the same user ID. In most cases you’ll probably want to update a user to set its state to “suspended” instead.