Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Azure Event Grid now supports publishing MQTT messages via HTTP, enabling backend systems to send messages to devices without maintaining persistent MQTT connections. This approach simplifies integration for applications that prefer stateless communication, uses secure authentication with Entra ID, and provides scalable, reliable delivery to MQTT clients. In this article, you learn how to use the HTTP Publish API, obtain the necessary credentials, and verify message delivery using popular tools like Bruno, and MQTTX.
Note
This feature is currently in preview.
This article explains how to publish MQTT messages via HTTP with Azure Event Grid.
Get your connection details
- Namespace fully qualified domain name (FQDN). Example:
contoso.westus3-1.ts.eventgrid.azure.net
. - Topic. Example:
devices/CXa-23112/prompt
. - Entra ID client credentials.
Get a bearer token
Run the following Azure CLI command to get a bearer token.
az account get-access-token --resource=https://<namespaceFQDN> --query accessToken -o tsv
Save this token to use in the Authorization: Bearer <TOKEN>
header.
Publish messages using HTTP
Here’s an example cURL command to simulate the HTTP Publish.
curl -X POST "https://contoso.westus3-1.ts.eventgrid.azure.net/mqtt/messages?topic=devices%2XXXX-0000%2Fprompt&api-version=2025-08-01-preview" \
-H "Authorization: Bearer <ENTRA_TOKEN_HERE>" \
-H "mqtt-qos: 1" \
-H "mqtt-retain: 0" \
-H "mqtt-response-topic: devices%2XXXX-00000%2Freply" \
-H "mqtt-correlation-data: XXXXXXX" \
-H "mqtt-user-properties: XXXXXXXXXXXX" \
-H "Content-Type: text/plain;charset=UTF-8" \
--data-raw "Please accept terms of licensing and agreement"
In this sample command:
- Topic is percent-encoded.
- Add optional headers for QoS, retain flag, response topic, user properties.
- Payload goes in the request body.
Verify in MQTTX
Use MQTTX or any MQTT library (like paho-mqtt Python) to subscribe to the same topic to confirm delivery.
- Create a new connection in MQTTX:
Host: contoso.westus3-1.ts.eventgrid.azure.net
Port: 8883 (TLS)
Client ID: same as your Entra Object ID
Username/Password: N/A — use certificate or token auth if configured
- Subscribe to the topic you used in the HTTP POST command.
- Run the HTTP Publish and watch for the message in MQTTX. You should see your payload appear.
If the publish succeeds, you see:
- HTTP Response: 204 No Content or 202 Accepted (depending on routing rules).
- MQTT client sees the message instantly.
Troubleshoot
- 401 Unauthorized? — If the token is missing or expired: You get 401 Unauthorized. Refresh your token.
- 403 Forbidden? — If the topic is invalid or you don’t have rights: 403 Forbidden. Check your topic or permissions.
- 500 Internal Server Error - If routing fails internally, check metrics and diagnostic Logs for your Event Grid namespace.
- Message doesn’t appear? — Ensure topic is percent-encoded in the URL, check broker routing config, and verify you’re using the same namespace.
Related content
For an overview of this feature, see HTTP Publish of MQTT messages with Azure Event Grid.