routeInputCreate
POST/v2/ena/routes/route-inputs
Create a single route input (event listener) to listen for messages (events) from a given producer (such as Pub/Sub API, Presence API, or Push Notifications API). In response, you'll obtain a unique string (routeInputId returned as data.id) representing the route input. This unique string is required to make other route input-related calls to Events & Actions API.
To create a route input, you must know the exact path to the PubNub message (event) type that this route input will listen for. This path must be specified in the endpoint object where you provide the messageTypeName and version identifying the most granular event type.
To identify the correct messageTypeName and version, follow this path:
- First, make a GET request to the
/v2/messages/sourcesendpoint and locate the source emitting the message (event) type you want to listen for. - Using the ID of the located source (
sourceId), make a GET call to the/v2/messages/sources/{sourceId}/producersendpoint to locate what produces this event type on a given source. - Finally, using the ID of the located producer (
producerId), make a GET call to the/v2/messages/producers/{producerId}/message-typesendpoint to search for all message (event) types that are available for a given producer and attach it asmessageTypeNameandversionwhen making a POST call to the/v2/routes/route-inputsendpoint.
Alternatively
- Make a GET request to the
/v2/messages/message-typesendpoint and locate the source emitting the message (event) type you want to listen for.
Example
Let's say you want to listen for all messages (events) emitted when a user subscribes to a channel to track channel presence.
After making a GET request to the /v2/messages/sources endpoint, you'll identify the channel source ID and use it call the /v2/messages/sources/{sourceId}/producers endpoint. The call will return a list of available producers for channels (currently only Presence), and using it, you can call the /v2/messages/producers/{producerId}/message-types endpoint to get the full list of the available message (event) types, out of which UserStartedSubscriptionToChannel is what you were looking for.
In this case, you'd use UserStartedSubscriptionToChannel as messageTypeName and 1.0.0 as version when calling /v2/routes/route-inputs and create a route input to listen for all events of type UserStartedSubscriptionToChannel.
Request
{
"data": {
"id": "string",
"endpoint": {
"platformName": "PUBNUB",
"messageTypeId": "string",
"messageTypeName": "string",
"version": "string"
},
"version": "string",
"name": "string",
"state": "DISABLED",
"filters": [
{
"type": "string",
"field": "string",
"value": "string"
}
]
},
"meta": {},
"errors": [
{
"code": "string",
"message": "string",
"path": "string"
}
]
}