Emit WebSocket event¶
Sends the data to every client subscribed to a custom WebSocket event whose subscription condition matches, whatever server the client is connected to.
| Method | POST |
| URL | /api/system-api/admin/emit-event-ws : admin is the user path of your account |
| Body | { name, eventData? } or an array of them |
| Answer | data : true |
| From code | g.sys.system.emitEventWS |
The call¶
Body
{ "name": "default/orders-updated", "eventData": { "recipientId": "42", "order_no": 1001, "status": "SHIPPED" } }
Body : several events
[
{ "name": "default/orders-updated", "eventData": { "recipientId": "42", "order_no": 1001 } },
{ "name": "stock-alerts", "eventData": { "sku": "WM-1", "qty": 2 } }
]
- The event must exist on the WebSocket Events page. A client receives the data when its subscription has no condition, or when the emitted data has the values of its
criteria. - To notify one person, put their id in the data and let their client subscribe with that id in
criteria.
From code¶
An unknown event answers 400 : WebSocket event not found with name ….
Access, headers and errors¶
- Over HTTP, a system API answers only once its settings open it :
TOKEN_ACCESS(the token of an API user whose group grants this system API) orIS_PUBLIC. Without settings it isNO_ACCESS: only your code (g.sys) and the admin panel reach it. - The settings can also keep the answer in the cache, or ask for the token of a person (
authProviders). Pre and post hooks run around it, as around any API. - It takes the request headers and answers the envelope.
401: no valid token, or the API isNO_ACCESS.403: no group grants it.400: the body is wrong, and the message names the key.
Related : All APIs · System API settings · System APIs from code