Skip to content

Exploring Postman's MQTT Integration with HiveMQ

by Kamiel Straatman
14 min read

Postman is a REST/HTTP API development and testing platform that offers a variety of features. It allows developers to easily create, use and share API requests and collections, automate testing, mock APIs, and monitor performance. Postman also provides collaboration and documentation tools enabling teams to work together more efficiently and communicate API behavior effectively. 

With the addition of MQTT, Postman is not only limited to working with Rest/HTTP APIs but can also support MQTT communication, define MQTT collections and develop MQTT-based documentation. At HiveMQ, we see ourselves as custodians of the MQTT protocol, and we are excited to see that MQTT support in Postman is now fully implemented. 

MQTT (Message Queuing Telemetry Transport) is a lightweight communication protocol designed for the Internet of Things (IoT). It enables devices to exchange data efficiently by subscribing to specific “topics” and publishing messages to those topics. MQTT is ideal for IoT applications like industrial automation and monitoring, sensor stations, and vehicle telemetry. It excels in low-bandwidth, real-time, and low-power scenarios.

HiveMQ is the trusted and industry-proven enterprise MQTT platform that facilitates reliable and scalable communication between MQTT clients. It’s extremely reliable under real-world stress, built for flexibility, security, and scale, and provides real-world solutions.

Postman, known for its versatility in API development and testing, can now also be effectively utilized for both MQTT communication and for managing HiveMQ brokers over the HiveMQ broker API. By leveraging this dual applicability of Postman's features, developers can streamline the testing, debugging, and management of MQTT-based systems connected to HiveMQ. 

Let's explore how to use Postman for both HiveMQ MQTT communication and API management and see why HiveMQ and Postman are best friends!  

Postman Support for MQTT

Postman's support for MQTT opens up a range of possibilities for developers working on IoT projects. Below is an overview on how Postman can be utilized for MQTT.

Postman provides a user-friendly interface for configuring MQTT connections. Developers can specify the broker URL, client IDs, credentials (if required), and other parameters directly from within the Postman application.

With Postman, developers can publish messages to MQTT topics effortlessly. Postman's intuitive interface lets users specify the payload, topic, QoS (Quality of Service) level, and other message attributes, simplifying the process of sending test messages to devices or applications.

Postman allows developers to easily subscribe to MQTT topics and view incoming messages in real-time. This simplifies the process of monitoring message traffic and ensures that subscriptions are correctly configured.

One of the prominent features introduced in our Postman’s MQTT support is the ability to view the telemetry data in a more readable fashion with visualization. As you receive data, you can see visualizations on your subscribed topics. No additional configuration is needed beyond subscribing to topics.

Postman's robust testing capabilities can be leveraged for MQTT-based systems. Developers can create test scripts to automate message publishing, subscription management, and validation, allowing for comprehensive testing of IoT applications.

Postman can be downloaded, free of charge and for all major platforms, here: https://www.postman.com/downloads

Using Postman for MQTT Communication

In this example we will be using the HiveMQ Community Edition, which is available for free.  However, you can substitute with any MQTT broker of your choice, hosted locally or in the cloud. 

To get started, first start Postman, click ‘new’ in your workspace and select the MQTT request type. In the connection bar, input mqtt://broker.hivemq.com along with MQTT version 5 (default) and hit the blue connect button.

Creating an MQTT request on postmanAfter connecting, you can send the payload that is referenced in the message field, which can be anything in MQTT, to the topic referenced in the topic field. Hit the blue Send button to actually send it. It shows an upward arrow in the response window.

Connecting an MQTT Broker and sending a test text message using PostmanIn the Topics tab you can subscribe to any topic you want to keep track of. Once a topic is received, these will be displayed in the response windows preceded with a downward-facing arrow.

Subscribing to an MQTT Topic on PostmanNow, if you publish a message to the topic you just subscribed to, the message is being published and subsequently being received as depicted below.

Publish an MQTT message to the topic you just subscribed to on PostmanThat is how simple it is to publish and subscribe to MQTT brokers and topics. Please feel free to use advanced features such as Quality of Service, retainment, persistent/clean sessions and the Last Will and Testament (LWT) ability. These standard MQTT features show the additional power of the MQTT protocol all demonstrated easily from within the Postman environment.

Leveraging Postman to Manage HiveMQ Cloud Brokers Over the API

Postman is well-known for its ability to set up and test API's, so we can use it for remote management of HiveMQ Cloud brokers.

We will demonstrate by setting up a HiveMQ Cloud Starter cluster that we will manage subsequently by the provided API from within Postman.

First, set up a private ‘starter’ cluster on cloud.hivemq.com. This can be done free of charge and without the use of a credit card.

When deployed, open the weblink https://console.hivemq.cloud and select the API access tab to create a new token. 

HiveMQ Cloud API tokens for integrating Postman with an MQTT Broker like HiveMQ CloudCreate the token with a proper name, a sensible expiration time and for ‘Full Access’. Copy and paste the token, along with the base API and REST URLs into a text editor and store in a safe location.

Create a new HiveMQ API tokenNow download the OpenAPI spec. Import the API by clicking the button in the top middle of the Postman application as a Postman definition and preferably along with creating a so-called collection. The collection will allow you to modify and add parameters and save them into an applicable environment or within the collection.

The definition needs you to create a number of variables that contain the orgId, the clusterId and the baseUrl. These can be found in the REST base URL as depicted below.

Breakdown of the structure of REST API tokenThe easiest way here is to create a new environment containing these variables and subsequently selecting the environment as the default in the upper right corner.

HiveMQ Cloud Starter Environment on PostmanOn the top collection level you are able to set the bearer token for all the API calls in that collection. Please copy the token you copied from the HiveMQ web interface into the token field (without trailing <enters>). 

Click the safe icon in the top right corner and set the authorization tab for each API in the collection you want to use to ‘Inherit auth from parent’.

 HiveMQ Cloud Public REST API on PostmanNow, when selecting an API call, set the parameters either to a fixed value or to environment variable fields in the environment by using the double brackets. An example is shown below.

HiveMQ Cloud integration on PostmanNow that all parameters are set along with the bearer authorization, an API call can be sent and should execute correctly.

Executing API Calls

Once we have all parameters, API endpoint, and security in place we can execute API against the running cluster. As an example we use the ‘List all MQTT clients’ which does not need further parameterization; simply select it, refer to the environment variables by adding them, in between double brackets as in the example, to the Value field under the variables section and hit the Send button. As a reply you would get a list of MQTT client names connected to the broker.

HiveMQ Cloud integration on PostmanAs another example, we use the ‘List all roles which also does not need further parameterisation; Simply select it, refer to the environment variables by adding them, in between double brackets as in the example, to the Value field under the variables section and hit the Send button. As a reply you would get a list of all roles defined on the broker.

HiveMQ Cloud MQTT Broker integration on PostmanAt this point you're ready to experiment with all the other calls available to you in the API collection. Don’t forget to save them so you won’t have to add parameter values over and over again.

Conclusion

Since the use of MQTT cloud brokers is becoming more prominent, the need for orchestrating them via deployment pipelines will also be more of a necessity. The HiveMQ Cloud brokers have excellent configurability over the provided secure API’s. The building and testing of these procedures’ programmatic interfaces can be done with ease from within Postman, making use of the provided HiveMQ API definitions.

Postman serves as a valuable tool for simplifying MQTT development and testing. It also provides a robust and well-defined Rest API tool to manage HiveMQ brokers programmatically. 

By providing a user-friendly interface, robust testing capabilities, and support for collaboration and documentation, Postman empowers developers to build and debug HiveMQ-based systems more efficiently. Whether you're working on a small IoT project or developing a large-scale M2M solution, Postman's support for MQTT and REST-APIs will streamline your development workflow and accelerate time-to-market. 

Kamiel Straatman

Kamiel is part of Solutions Engineering team at HiveMQ. Based out of the Netherlands, Kamiel is an IoT enthusiast with many years of experience working in the data center domain and Azure & AWS cloud architectures. He specializes in ICT infrastructure consulting with a strong focus on cloud, cloud automation, datacenter transformation, security, storage and networking.

  • Contact Kamiel Straatman via e-mail
HiveMQ logo
Review HiveMQ on G2