Service Events
Event registration, emitEvent call, communication with automations, and restrictions.
Machine translation
The service can inform about the user's action — for example, that the report is ready — and run the associated automation. The administrator first creates an event definition in the interface, and then the service code calls it via the SDK. Method
emitEvent it does not create a new definition or create automation.
- Save the service so that it has a permanent ID.
- Open the tab Events with a zipper badge. You can open the registry for the service using the event button in the general list of services.
- Click Create an event. In a separate window, specify the name, the technical name in Latin (
report_ready), description and status of "Event enabled". - Copy the sample call from the list item. The server will generate the full code itself: for service No. 42, you will get
custom.service_42.report_ready. - In Administrator → Automation open the script and click the square button with the zipper Service Event in the header next to the deletion. In the window that opens, find the event by name or service, mark it and click Select an event. Check the configuration, handler, and destination, save it, and enable automation.
- Trigger an event from the published service after the desired user action.
The same local name is valid in different services: the prefixes will be different. The server also divides events by company. The name and description can be changed, but the technical name cannot be edited after creation. Renaming the service does not change the event code. You can register up to 100 events per service; search and pagination help you work with the list. Disabling it prohibits new calls, and already received events continue to be processed.
Calling from JavaScript
For an embedded service, an instance synchra already provided by the engine. Run the example inside the asynchronous button handler after checking the integration:
if (!(await synchra.isSynchraIntegrated())) {
throw new Error('Откройте сервис внутри Synchra.');
}
// Один ключ на одну операцию. Сохраните его, если потребуется повтор запроса.
const requestKey = crypto.randomUUID();
const result = await synchra.emitEvent(
'report_ready',
{ report_id: '125' },
{ requestKey },
);
if (result.preview) {
// Предпросмотр: реального запуска нет.
} else {
// result.event_id — подтверждение приёма в очередь, не завершения сценария.
}
The local name is passed to the SDK report_ready. Full code
custom.service_42.report_ready it is needed for the automation trigger, not for the first argument. emitEvent. You do not need to transmit the user's token, company ID, or system event type in the call: they are determined by an authorized bridge.
payload — A JSON object of up to 32 KB. For one action, keep the same
requestKey if repeated: the same key and data will not create a repeat event. With different data, the previous key will give a 409 error. The keys are stored for at least 24 hours. Without requestKey each call receives a new key and is considered a separate operation. Disable the button at the time of sending and show the user the download, reception success or error; do not trigger an event with each render and do not make endless automatic repetitions.
Accessibility and restrictions
emitEvent — extension of the built-in SDK web service. It should not be considered a method of any installed version of the npm package. @synchra24/app: the web engine provides it in the editor. The mobile bridge does not support this call yet. The preview returns preview: true and accepted: false; real automations don't run.
To create events, you need the ability to Applications the subscription also includes the right to edit the services. To set up related automation — API integration and the right to manage integrations. Events only work for employees with access to the service.
The number of submissions is limited so that accidental repeated clicks do not overload the system. Up to 30 calls per minute are allowed per employee and event; general service and company restrictions also apply. If the calls are too frequent, you need to wait before replaying. If the sending failed, the service should show an error, not a successful launch message.
For more information about the setup and history, see the article "Synchra24 event Launch".