Emit event¶
Emits an event of the account : its listeners run with the data, and the call answers what they returned.
| Method | POST |
| URL | /api/system-api/admin/emit-event : admin is the user path of your account |
| Body | { name, eventData?, executeListeners? } or an array of them |
| Answer | data : the event with outputArr, one entry per listener |
| From code | g.sys.system.emitEvent |
The call¶
Body
{ "name": "order-placed", "eventData": { "order_no": 1001 }, "executeListeners": [ "send-invoice" ] }
Answer
{
"success": true,
"statusCode": 200,
"data": { "name": "order-placed", "eventData": { "order_no": 1001 }, "executeListeners": [ "send-invoice" ], "outputArr": [ { "listenerName": "send-invoice", "output": { "notified": true } } ] }
}
Body : several events
[
{ "name": "order-placed", "eventData": { "order_no": 1001 } },
{ "name": "stock-changed", "executeListeners": [ "sync-warehouse", "alert-low-stock" ] }
]
executeListenersnames the listeners to run ; absent, every listener of the event runs.- A chain which comes back to an event already running is stopped : no infinite loop.
From code¶
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