MQTT Broker REST API Documentation

MQTT REST API Documentation

 

Introduction

While building an IoT application, there is a need to control and manage the edge devices from the manager application. So, the Bevywise MQTT Route provides a REST API to integrate MQTT Broker. This API will help you control your edge devices via the REST API. You can send messages, add new authentication keys, get client details, and do more via the API. This documentation provides a complete guide for the developers to build IoT applications using the RESTful API of MQTT Broker.

Basics

For Post

Set raw data in body.

All the parameter fields should be given as a parameter.

Once the authentication credentials you enter are verified, you will receives response. Then  create authorization and set bearer token. And for all APIs except login API, it is necessary to set authorization.

For GET

GET Method sends request to the server to collect data.

Set key and value in header type.

Set content-type and authorization in key field.

Set the value for content-type as application/json and the bearer token value.

Log-in API

This MQTT Rest 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

Parameters:

 

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 APIs 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 APIs. 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

Parameters:

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

Parameters:

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

Parameters:

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

Parameters:

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

Parameters:

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'

Download Bevywise MQTT Broker for free