Subscribing to topics
Prerequisites
You must have a WebSocket secure connection to the switch.
Access to the switch REST API must be enabled. The REST API access mode can be either read-only or read/write.
Procedure
Using the WebSocket secure connection, send a subscribe message that contains the topics to which you want to subscribe and a poll interval hint, if any:
For example:
{
"type": "subscribe",
"topics": [
{
"name": "/rest/v1/system/vrfs"
},
{
"name": "/rest/v1/system/bridge/vlans/DEFAULT_VLAN_1?attributes=admin,oper_state_reason"
}
],
"hint": 5
}
If the subscriber already has a subscription to the specified topic, the following error is returned:
{ "type":"error", "message":"The topic or combination of topics have been already subscribed." }
If the URI in the topic name specifies a resource that is not in the configuration and state database, the following error is returned:
{"type":"error","message":"Object not found."}
Example of a message returned by a successful subscription attempt:
{
"type": "success",
"subscriber_name": "4bcf8uka90ki",
"subscription_name": "ns83n58dky",
"data": [
{
"topicname": "/rest/v1/system/bridge/vlans/DEFAULT_VLAN_1?attributes=admin,oper_state_reason",
"resources": [
{
"operation": "",
"uri": "/rest/v1/system/bridge/vlans/DEFAULT_VLAN_1",
"values": {
"admin": "up",
"oper_state_reason": "no_member_port"
}
}
]
},
{
"topicname": "/rest/v1/system/vrfs",
"resources": [
{
"operation": "",
"uri": "/rest/v1/system/vrfs/default",
"values": {}
},
{
"operation": "",
"uri": "/rest/v1/system/vrfs/mgmt",
"values": {}
}
]
}
]
}