MQTT Broker REST API Documentation

Introduction:


While building IoT application, there is a need to control and manage the edge devices from the manager application. This API will help you control your edge devices via the REST API. You an send messages, add new authentication keys, get client details and do more via the API.

Log-in API

This API helps you login to MQTT broker user interface by using username and password in broker.conf file.

Method

Post


http://(Server-IP):8080/api/login

Parameter:

Parameter Value Details
username username in broker.conf file
password password in broker.conf file

Response:

On Success:


        {
              "access_token": "< token >",
              "status": "Logged In"
        }

On Failure:


        { 
             "status":"Invalid Login"
        }

Parameters are missing:

        '(Parameter Name) parameter is missing -'
        

Authorization Header

Authorization header is the method of providing authentication information. All the API’s below are accessing data specific to a user who logged-in to the MQTT broker. So, we need to do the session token to all the API’s. The Session token should be set as part of the Request Header to provide authentication information. The format of the Authorization header is

         Authorization: < access_token >    
         

Error Responses On using Authorization Header:

        If Authorization header is not defined 

        {
            "detail": "Authentication credentials were not provided."
        }

            If Token is Invalid
        {
            "detail": "Invalid token."
        }    
       

Clientsend

Send message to the particular client based on the client ID. This can be sent to a client that has subscribed or not subscribed to the topic.

Method

POST


  http://(Server-IP):8080/clientsend
 

Parameter:

Parameter Value Detail
clientid Client id or device id to which the message needs to be sent.
topic Publish topic to which the particular client is subscribed to.
message Message to be sent
QoS QoS Level (Optional). If not set, QoS will be 0
retain Retain Flag (Optional), If not set, Retain will be 0

Response:

On Success:

                   
      'Message has been sent to (Client_ID)'

On Failure:

      'Message could not be delivered to (Client_ID)'

Parameters are missing:

       'The required parameter is missing - (Parameter Name)'
            

Invalid Token:

      'Invalid Token access'

Sendall

Send message to all the devices who subscribed to the Published topic.

Method

POST



http://(Server-IP):8080/sendall  

Parameter:

Parameter Value Detail
topic Publish topic to which the particular client is subscribed to.
message Message to be sent
QoS QoS Level (Optional). If not set, QoS will be 0
retain Retain Flag (Optional), If not set, Retain will be 0

Response:

On Success:

      'Message has sent to subscribers of topic - (topic)'

On Failure:

      'Message could be delivered to subscribers of topic - (Topic)'

Parameters are missing:

       'The required parameter is missing - (Parameter Name)'  
          

Invalid Token:

      'Invalid Token access'

Add Authentication

Automatically add Authentication credentials to MQTT Broker when Authentication Enabled.

Method

POST


http://(Server-IP):8080/addauth  

Parameter:

Parameter Value Detail
username username to be added
password password to be added for the given username

Response:

On Success:

                           
      '('Auth has been added'-'(username)')'

On Failure:

      '('Auth hasnt added'-'(username')'

Parameters are missing:

        'The required parameter is missing - (Parameter Name)'       
     

Invalid Token:

      'Invalid Token access'

Editauth API

This API helps you to edit the previously created authentication credentials.

Method

POST


http://(Server-IP):8080/editauth  

Parameter:

Parameter Value Detail
username previously created username
new_password new password

Response:

On Success:

                           
      'Authentication credentials updated successfully'

On Failure:

      'Authentication credentials can't be updated'

Parameters are missing:

       'The required parameter is missing - (Parameter Name)'
            

Invalid Token:

      'Invalid Token access'

Remove Authentication

Automatically remove Authentication credentials to MQTT Broker when Authentication Enabled.

Method

POST


http://(Server-IP):8080/removeauth  

Parameter:

Parameter Value Detail
username username to be removed
password password to be removed for the given username

Response:

On Success:

                 
      '('Auth has been removed'-'(username)')'

On Failure:

      '('Auth hasnt removed' - '(username')'

Parameters are missing:

       'The required parameter is missing - (Parameter Name)'   
         

Invalid Token:

      'Invalid Token access'

Connected Device List

List all Connected Device.

Method

GET


http://(Server-IP):8080/connecteddevices  

Response:

When Device Connected:

                    
      '{"clientno1":"clientid1" , "clientno2" : "clientid2"}'

When Device not connected

      '{}'

Parameters are missing:

       'The required parameter is missing - (Parameter Name)'  
          

Invalid Token:

      'Invalid Token access'

Client Count

Automatically remove Authentication credentials to MQTT Broker when Authentication Enabled.

Method

GET


http://(Server-IP):8080/graph/client_count

Response:

When Device Connected:

                     
      '{"clientcount": (no of devices)}'

When no devices are connected:

      '{}'

Parameters are missing:

       'The required parameter is missing - (Parameter Name)'   
         

Invalid Token:

      'Invalid Token access'

Logout

This API helps you log out to MQTT broker user interface by using username and password in broker.conf file.

Method

POST


http://(Server-IP):8080/api/logout  

Parameter:

Parameter Value Detail
username username in broker.conf file
password password in broker.conf file

Response:

On Success:


         {
               "status": "Logged Out"
         }

On Failure:


         { 
                "status":"Invalid Logout"
         }

Invalid Token:

       'Invalid Token access'