# Message Publish

# Message Publish

# URI

POST /mqtt/publish

# Request Message

NameTypeRequiredDefaultDescription
topicStringOptionalFor topic and topics, with at least one of them specified
topicsStringOptionalMultiple topics separated by ,. This field is used to publish messages to multiple topics at the same time
clientidStringRequiredClient identifier
payloadStringRequiredMessage body
encodingStringOptionalplainThe encoding used in the message body. Currently only plain and base64 are supported. Default is plain
qosIntegerOptional0QoS level
retainBooleanOptionalfalseWhether it is a retained message, default is false

# Response Message

NameTypeDescription
codeInteger0

# Request Example

curl -u app_id:app_secret -X POST -d '{"topic": "topic/a","clientid": "emqx_c_1","payload": "Hello EMQX"}' {api}/mqtt/publish
1

# Response Example

{
  "code": 0
}
1
2
3

# Batch Message Publish

# URI

POST /mqtt/publish_batch

# Request Message

NameTypeRequiredDefaultDescription
[].]opicStringOptionalFor topic and topics, with at least one of them specified
[].topicsStringOptionalMultiple topics separated by ,. This field is used to publish messages to multiple topics at the same time
[].clientidStringRequiredClient identifier
[].payloadStringRequiredMessage body
[].encodingStringOptionalplainThe encoding used in the message body. Currently only plain and base64 are supported. Default is plain
[].qosIntegerOptional0QoS level
[].retainBooleanOptionalfalseWhether it is a retained message, default is false

# Response Message

NameTypeDescription
codeInteger0

# Request Example

curl -u app_id:app_secret -X POST -d '[{"topic": "a/b","clientid": "emqx_c_1","payload": "Hello EMQX"},{"topic": "a/b","clientid": "emqx_c_1","qos": 2,"payload": "Hi EMQX"}]' {api}/mqtt/publish_batch
1

# Response Example

{
    "data": [
        {
            "topic": "a/b",
            "code": 0
        },
        {
            "topic": "a/b",
            "code": 0
        }
    ],
    "code": 0
}
1
2
3
4
5
6
7
8
9
10
11
12
13