Stand with Ukraine flag
Try it now Pricing
MQTT Broker
Community Edition Professional Edition Cloud Edge PE Edge IoT Gateway License Server Trendz Analytics Mobile Application PE Mobile Application MQTT Broker
API > REST APIs > User Management
Getting Started Documentation Installation Architecture
FAQ
On this page

User Management

By default, the system is initially established with a singular admin user, with username [email protected] and password sysadmin.

However, when operating in a production environment, it is strongly advised to create a new admin user, either remove the default user entirely or modify the password associated with the aforementioned user.

Throughout this documentation, all provided examples will employ the curl command to execute REST requests, thus showcasing practical implementations of the API interactions.

Authentication

To carry out administrative operations with the broker, it is imperative to log into the system and obtain an Access Token. This Access Token is essential for authenticating and authorizing your administrative actions.

To acquire the Access Token, you can execute the following command:

1
2
3
4
5
6
curl --location --request POST 'http://localhost:8083/api/auth/login' \
--header 'Content-Type: application/json' \
--data-raw '{
    "username":"[email protected]",
    "password":"sysadmin"
}'

Please be aware that if the broker is installed on a remote server, you must substitute “localhost” in the provided command with either the public IP address of the server or a designated domain name. Moreover, ensure that port 8083 is accessible publicly to establish the necessary connection. Additionally, remember to replace the “username” and “password” values in the command with the appropriate and valid credentials specific to your setup.

Upon successful authorization, the response will include a valuable piece of information known as the token. It is crucial to utilize this token for all subsequent administrative requests to TBMQ. To streamline the process, you can either assign the value of the token field to an environment variable named ACCESS_TOKEN or directly replace occurrences of the $ACCESS_TOKEN string within the requests outlined in this tutorial.

1
export ACCESS_TOKEN=PLACE_YOUR_TOKEN_HERE
Get all users
1
2
curl --location --request GET "http://localhost:8083/api/admin?pageSize=50&page=0" \
--header "X-Authorization: Bearer $ACCESS_TOKEN"

Within the system, every user entity possesses a distinct and unique identifier known as the id. This id serves as a reference point and can be utilized to perform operations such as updating or deleting users.

Create/update user
1
2
3
4
5
6
7
8
9
10
curl --location --request POST 'http://localhost:8083/api/admin' \
--header "X-Authorization: Bearer $ACCESS_TOKEN" \
--header 'Content-Type: application/json' \
--data-raw '{
    "id":$USER_ID,
    "email":"[email protected]",
    "password":"test",
    "firstName":"test",
    "lastName":"test"
}'

If $USER_ID is null or id field is absent in the request body, the new admin user will be created, otherwise the user with $USER_ID identifier will be updated.

Delete user
1
2
curl --location --request DELETE 'http://localhost:8083/api/admin/$USER_ID' \
--header "X-Authorization: Bearer $ACCESS_TOKEN"

Paste actual ID of the user you want to delete instead of $USER_ID.