whitemarket Documentation For Partners

SSE

Server-Sent Events (SSE) is a technology that allows a server to push updates directly to the client without requiring client requests. SSE provides one-way communication from the server to the client over the HTTP protocol, offering a straightforward and efficient way to transmit real-time data. Unlike WebSocket, which supports bidirectional communication, SSE focuses on server-initiated data transmission, making it ideal for use cases such as updating news feeds, sports scores, and other scenarios where continuous updates from the server to the client are essential.

Endpoint

https://api.white.market/sse_endpoint

Playground

SSE Playground

Example on JS to connect

    const url = new URL('https://api.white.market/sse_endpoint');
    const token = '<Place here JWT token from auth_token mutation>'    

    url.searchParams.append("cf_connect", JSON.stringify({
        'token': token,
        'debug': true,
        'subs': {"market_products_updates":{}}
    }));

    const es = new EventSource(url);

    es.addEventListener("open", (event) => {
        console.log('Open');
    });

    es.addEventListener("message", (event) => {
        console.log(event.data.message); // event.data.message contain JSON encoded string. See format below.
    });

    es.addEventListener("error", (event) => {
        if (event.type === "error") {
            console.log('Error', event.message);
        } else if (event.type === "exception") {
            console.log('Error', event.message + ' ' + event.error);
        }
    });

    es.addEventListener("close", (event) => {
        console.log('Close');
    });

General format

{
   "channel":"CHANNEL_NAME",
   "pub":{
      "data":{
         "message":"ENCODED_AND_ESCAPED_JSON_CONTENT"
      }
   }
}

When receiving, you need to unescape and json decode to get the data

Example

{
   "channel":"market_products_updates",
   "pub":{
      "data":{
         "message":"{\"type\":\"market_product_added\",\"content\":{\"id\":\"1ef6c2b5-7f94-67c0-8e23-0242ac15000b\",\"app_id\":\"730\",\"asset_id\":\"36857146063\",\"class_id\":\"469440539\",\"instance_id\":\"302028390\",\"price\":\"0.020\",\"name_hash\":\"G3SG1 | Green Apple (Minimal Wear)\",\"inspect_url\":\"steam:\\\/\\\/rungame\\\/730\\\/76561202255233023\\\/+csgo_econ_action_preview%20S76561198283251328A36857146063D14015389653147072601\",\"delivery_type\":\"semi\"}}"
      }
   }
}

Messages

Click here