# Topic Subscription

# Subscribe

# URI

POST /mqtt/subscribe

# Request Message

NameTypeRequiredDefaultDescription
topicStringOptionalTopic, with at least one of the topics specified
topicsStringOptionalMultiple topics separated by ,. This field is used to subscribe to multiple topics at the same time
clientidStringRequiredClient identifier
qosIntegerOptional0QoS level

# Response Message

NameTypeDescription
codeInteger0

# Request Example

curl -u app_id:app_secret -X POST -d '{"topic": "d","qos": 1,"clientid": "emqx_c_1"}' {api}/mqtt/subscribe
1

# Response Example

{
"code": 0
}
1
2
3

# Unsubscribe

# URI

POST /mqtt/unsubscribe

# Request Message

NameTypeRequiredDefaultDescription
topicStringOptionalTopic
clientidStringRequiredClient identifier

# Response Message

NameTypeDescription
codeInteger0

# Request Example

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

# Response Example

{
"code": 0
}
1
2
3

# Batch Subscribe

# URI

POST /mqtt/subscribe_batch

# Request Message

NameTypeRequiredDefaultDescription
[].topicStringOptionalTopic, with at least one of the topics specified
[].topicsStringOptionalMultiple topics separated by ,. This field is used to subscribe to multiple topics at the same time
[].clientidStringRequiredClient identifier
[].qosIntegerOptional0QoS level

# Response Message

NameTypeDescription
codeInteger0
dataArray of ObjectsAll the subscription information
data[].clientidStringclientid
data[].topicStringTopic
data[].codeInteger0

# Request Example

curl -u app_id:app_secret -X POST -d '[{"topic": "a", "qos": 1, "clientid": "testtopic/#"}, {"topic": "topic/a", "qos": 1, "clientid": "emqx_c_1"}]' {api}/mqtt/subscribe_batch
1

# Response Example

{
    "data": [
        {
            "topic": "a",
            "code": 112,
            "clientid": "testtopic/#"
        },
        {
            "topic": "topic/a",
            "code": 0,
            "clientid": "emqx_c_1"
        }
    ],
    "code": 0
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

# Batch unsubscribe

# URI

POST /mqtt/unsubscribe_batch

# Request Message

NameTypeDescription
[].topicStringTopics, with topics specifying at least one of them
[].topicsStringMultiple topics split by ,, use this field to subscribe to multiple topics at the same time
[].clientidStringclientid
[].qosIntegerQoS Level

# Response Message

NameTypeDescription
codeInteger0
dataArray of ObjectsAll subscriptions
data[].clientidStringclientid
data[].topicStringSubscription Topics
data[].codeInteger0

# Request Example

$ curl -u app_id:app_secret -X POST -d '[{"topic": "a","clientid": "emqx_c_1"}]' {api}/mqtt/unsubscribe_batch
1

# Response Example

{
  "data": [
    {
      "topic": "a",
      "code": 0,
      "clientid": "emqx_c_1"
    }
  ],
  "code": 0
}
1
2
3
4
5
6
7
8
9
10