Links

Sending data to W3bstream

W3bstream provides two different network service endpoints that allow sending data messages to the various running projects.
A W3bstream data message is a JSON object composed of two properties:
  • the W3bstream header is a nested object containing W3bstream-related values, and
  • the message payload is a string that contains the actual message to be processed by the target event handler in W3bstream.
An example message is shown below:
{
"header": {
"pub_id": "my_publisher_id",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJQYXlsb2FkIjoiNDUwNTI4NzAxMjc2NTcwMyIsImlzcyI6InNydi1hcHBsZXQtbWdyIiwiZXhwIjoxNjY4Mzk4MDYxfQ._Q5ZaBP5FSa09s0FCn7CBcMCty9hkM5TDu5q1wTvwB8",
"event_type": "DEVICE_EVENT_0001",
"pub_time": 1667343986249
},
"payload": "VGhpcyBpcyB0aGUgbWVzc2FnZSBwYXlsb2FkCg=="
}

The header

The header nested object is intended for W3bstream to authorize the message and route it to the right handler.
pub_id:<string> is the identifier of a valid Publisher defined in the destination W3bstream Project.
token:<string> is the authorization token associated with the Publisher Identifier (pub_id)
event_type:<string> this can be anything, as long as it's matched in an event strategy of the destination W3bstream Project
pub_time:<number> this is the timestamp when the message was actually sent.

The payload

The message payload must be a string encoded using the base64 scheme and it can be anything. Once the message reaches W3bstream and a strategy rule is matched for the event, then the decoded payload string can be accessed by the target handler function using the GetData W3bstream function.

Sending data using HTTP

The W3bstream HTTP API default port is 8888.
the event/project_name the endpoint of the HTTP API can be called to send data messages to a specific project:
post
w3bstream_ip_address:8888
/srv-applet-mgr/v0/event/<PROJECT_NAME>
Send a message to a specific W3bstream Project
Notice: project names are case-sensitive in W3bstream
The example below uses curl to send a message over HTTP where the recipient project is called NftMinter and it's intended to raise an event called "MINT" inside W3bstream:
curl --location --request POST 'localhost:8888/srv-applet-mgr/v0/event/NftMinter' --header 'Content-Type: text/plain' --data-raw '{
"header": {
"event_type": "MINT",
"pub_id": "my_publisher_id",
"pub_time": 1666211451,
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e"
},
"payload": "VGhpcyBpcyB0aGUgbWVzc2FnZSBwYXlsb2FkCg=="
}'

Sending data using MQTT

Notice: Client authentication with MQTT certificates is not supported yet.
The W3bstream MQTT broker default port is 1883.
To send a message to a specific W3bstream Project using MQTT, the recipient project name should be used as the topic when publishing the MQTT message.
The example below uses mosquitto as an MQTT client to send a message to a local W3bstream node where the recipient project is called NftMinter in W3bstream:
Notice: project names are case-sensitive in W3bstream
mosquitto_pub -h localhost -t PROJECT_NAME -m '{
"header": {
"pub_id": "my_publisher_id",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJQYXlsb2FkIjoiNDUwNTI4NzAxMjc2NTcwMyIsImlzcyI6InNydi1hcHBsZXQtbWdyIiwiZXhwIjoxNjY4Mzk4MDYxfQ._Q5ZaBP5FSa09s0FCn7CBcMCty9hkM5TDu5q1wTvwB8",
"event_type": "DEVICE_EVENT_0001",
"pub_time": 1667343986249
},
"payload": "VGhpcyBpcyB0aGUgbWVzc2FnZSBwYXlsb2FkCg=="
}'