Manage event subscriptions
Subscribe functions to events, remove subscriptions, and see which functions listen to an event. Changing subscriptions requires an organization owner or admin, or another cloud user with access to the site; see Security and limits.
In the Console
- Open your app and select Events. Each event shows its subscribers.
- To subscribe, select Subscribe on an event, choose functions in Select Functions, and confirm.
- To remove a subscription, select Unsubscribe next to the function and confirm.
With the REST API
REST requests use an Authorization: Api-Key TARUVI_API_KEY header. Use the
numeric function id returned by GET /api/apps/APP_SLUG/functions/, and an
event name from Event types.
List events
Any signed-in caller can list event names:
curl -sS "${TARUVI_SITE_URL}/api/cloud/events/" \
-H "Authorization: Api-Key ${TARUVI_API_KEY}"
The response's data.events is a list of names such as RECORD_CREATE.
Subscribe a function
curl -sS -X POST "${TARUVI_SITE_URL}/api/cloud/events/EVENT_NAME/subscribe/" \
-H "Authorization: Api-Key ${TARUVI_API_KEY}" \
-H "Content-Type: application/json" \
-d "{\"function_id\":${FUNCTION_ID}}"
| Result | Status |
|---|---|
| Subscribed | 201 Created, with the subscription's event and function |
| Unknown function | 400 Bad Request |
| Already subscribed | 400 Bad Request — the message includes already exists |
| Unknown event name | 400 Bad Request — the message includes Invalid event type |
| Caller isn't allowed to manage subscriptions | 403 Forbidden |
Unsubscribe a function
curl -sS -X POST "${TARUVI_SITE_URL}/api/cloud/events/EVENT_NAME/unsubscribe/" \
-H "Authorization: Api-Key ${TARUVI_API_KEY}" \
-H "Content-Type: application/json" \
-d "{\"function_id\":${FUNCTION_ID}}"
This returns 200 OK when the subscription is removed. If the function wasn't
subscribed, the request returns an error; check the subscribers list below to
confirm the current state.
List an app's subscribers
curl -sS "${TARUVI_SITE_URL}/api/apps/APP_SLUG/events/EVENT_NAME/" \
-H "Authorization: Api-Key ${TARUVI_API_KEY}"
The response includes:
event— the event name;app—{ id, name, slug };total_subscribers— the number of this app's functions subscribed;subscribers— each function'sfunction_id,function_name,function_slug, andfilter_conditions.
An unknown app returns 404; an unknown event name returns 400.
Check that a subscription works
- Do the action that fires the event — for example, create a record for
RECORD_CREATE. - Open the function's runs in Logs and invocations and look for a new run triggered by the event.
For PRE_USER_CREATE, test with a throwaway user: if the function fails or takes
longer than 30 seconds, the user isn't created.