Websocket Connection
Websockets are used to receive real-time updates from the Blink API.
Implemented using the GraphQL over WebSocket Protocol
Available Websocket Events
myUpdateslnInvoicePaymentStatusrealtimePriceprice
Websocket Endpoint
wss://ws.blink.sv/graphql
Apollo Playground
To try the subscriptions and explore the schema use the
Apollo Playground for Blink subscriptions
After loading the playground:
- open the
SANDBOXconnection settings and set:
wss://ws.blink.sv/graphqlas theSubscriptionsURL thenSave.
Authentication with X-API-KEY
WebSocket connections require authentication using your API key from the Blink Dashboard.
Unlike regular HTTP requests where the API key is sent in a header, for WebSocket connections, the API key is included in the connection initialization payload:
{
"type": "connection_init",
"payload": {
"X-API-KEY": "blink_your_api_key_here"
}
}
This authentication method is required for accessing user-specific subscription data like myUpdates.
Postman
Try the websocket connection examples in the Blink API collection
To use the raw websocket protocol in Postman there are a few steps to follow:
Header to Use
- Define the protocol
Sec-WebSocket-Protocol: graphql-transport-ws
Send the connection_init Request
- to get a
connection_ackresponse{
"type": "connection_init",
"payload": {}
}
For Authenticated Requests
- include the api key in the payload of the
connection_initrequest{
"type": "connection_init",
"payload": {
"X-API-KEY": "<your api key>"
}
}
Send a Subscription Request
- use the format described in the GraphQL over WebSocket Protocol
- need to paste the message in place of the
connection_initmessage to continue using the same connection{
"id": "1",
"type": "subscribe",
"payload": {
"query": "subscription { price( input: { amount: 100 amountCurrencyUnit: BTCSAT priceCurrencyUnit: USDCENT } ) { errors { message } price { base offset currencyUnit } }}",
"variables": {}
}
}
Websocat
-
Install with:
- Linux (with a Rust toolchain installed)
cargo install websocat - MacOS
brew install websocat
- Linux (with a Rust toolchain installed)
-
Connect to the websocket endpoint
websocat ${websocket_endpoint} -H 'Sec-WebSocket-Protocol: graphql-transport-ws' -v