WebSocket API
Use the B2Core Websocket API to monitor execution of asynchronous deposits.
Connect to a WebSocket server
To get access to the B2Core WebSocket API, do the following:
Establish a connection to the
engine.io
server and obtain the unique session identifier by sending the following request:
GET http://host.name/socket.io/?EIO=3&transport=polling&t=OEUZJMz
where:
"EIO=3" # The current version of the Engine.IO protocol
"transport=polling" # The HTTP long-polling transport
"t=OEUZJMz" # A hashed timestamp for cache busting
A response from the engine.io
server includes the following message:
{
"type": "open",
"data": {
"sid": "36Yib8-rSutGQYLfAAAD", // The unique session identifier
"upgrades": ["websocket"], // A list of possible transport upgrades
"pingInterval": 25000, // The 1st parameter set for the heartbeat mechanism
"pingTimeout": 5000 // The 2nd parameter set for the heartbeat mechanism
}
}
Upgrade the transport to
websocket
by sending the following request:
GET ws://host.name/socket.io/?EIO=3&transport=websocket&sid=36Yib8-rSutGQYLfAAAD
where:
"EIO=3" # The current version of the Engine.IO protocol
"transport=websocket" # The websocket transport that is being probed
"sid=36Yib8-rSutGQYLfAAAD" # The unique session identifier obtained at the previous step
To upgrade the packet type, send the message
5
to the server.Send the “ping” message
2
and receive the “pong” message3
as a response from the server, indicating that the transport has been successfully upgraded towebsocket
.
Subscribe to the user events channel
To get real-time updates about execution of asynchronous deposits, subscribe to the private-frontend_users
channel.
Note
To subscribe to this private channel, you must specify a client access token to the Front Office and a client identifier.
To learn how to authenticate in the Front Office, refer to the Front Office API authentication methods.
One of the following event types is returned:
deposit_done
deposit_failed
GET ws://host.name/socket.io/?EIO=3&transport=websocket&sid=36Yib8-rSutGQYLfAAAD
where:
"EIO=3" # The current version of the Engine.IO protocol
"transport=websocket" # The websocket transport
"sid=36Yib8-rSutGQYLfAAAD" # The unique session identifier
[
"subscribe",
{
"channel":"private-frontend_users.{frontendUserID}",
"auth":{
"headers":{
"i-am-api":"",
"Authorization":"Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiI4ODYiLCJpYXQiOjE2NjQ4OTE2NzgsImV4cCI6MTY2NDg5Mjg3OCwiaXNzIjoiaHR0cHM6XC9cL3RjYS5hcGkuZG9ja2VyOjg0NDMifQ.nUdoU0nuAm2OLbhXCNvl7Hbzi-Xc875i6BFFkC4WI2xvREsrgABUsi-qYmFjSYxRSXcpOggSc15g67YF4u0WXicWSKqpihwIeJSvpIMoDn2mjAGiaR2e5p493eMNsTZ6lteo1SAXvlRDDVdGK-7H7Lf9h57q3bGTKFuTRMy3rnvKJWA0P4PoXHa-7uerWg9PD7zgNXPvSywZtYUioXyJbgIzSbh1fiEoi3vaixPEDuDiAUyWZ68N4O4IVP3EaJA4KN2o6TsXbnEpFjmGf0C8TaDjMIpi9ZtwgYclLpUL4MTOHmHfJnZO_tATEh37STpzexJdP2vv4fe0GUTyUL131Q"
}
}
}
]
where:
"Authorization": # The access token generated for a client
"{frontendUserID}": # The client identifier
Response
A response contains a message providing data about an occurred event.
- uuid string
The universally unique identifier (UUID) assigned to an event (always
null
).- date string
The date and time when an event occurred.
- event string
The event type:
deposit_done
deposit_failed
- data object
The details about a deposit transaction.
Show object fields- invoice integer
The invoice identifier.
- action string
The webhook triggered by this event, indicating whether any further actions are required in the Front Office.
- transactionId integer
The identifier of a deposit transaction.
{
"uuid": null,
"date": "20221002T11:20:22+00:00",
"event": "deposit_done",
"data": {
"invoice": 1,
"action": "api.stage.b2broker.org/deposits/detyj-234dfsgh-e/webhooks",
"transactionId": 1
}
}
{
"uuid": null,
"date": "20221002T11:20:22+00:00",
"event": "deposit_failed",
"data": {
"reason": "Fail reason description"
}
}