# Publish MQTT Message Action

This provides a way to publish message to MQTT Broker. Before adding Publish MQTT Message Action, user has to define a [**MQTT Connection**](/connections/mqtt-connection.md). User need to provide following parameters to publish message to MQTT Broker.

#### PublishTopic

* &#x20;User need to provide MQTT Topic on which data will be published.

#### QoS

MQTT QoS value. Default is 1.

#### Function

* Javascript code to build mqtt message.
* "topic","message" and "payload" objects are available in this code, function can be used to set message body and topic from payload before sending to MQTT.
* Setting topic here overrides already defined PublishTopic.

```
//Example 1

message = payload;
topic = "somenewtopic";
```

#### Connection ID

User need to provide a Connection ID of MQTT connection.

![Add Publish MQTT Message Action](/files/BBDh5yktsSMBbKi38KKB)

Please note the following points:

{% hint style="info" %}

* "payload" object is supplied from Action Trigger like Rules, Action Command etc.
  {% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.thingsup.io/actions/publish-mqtt-message-action.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
