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:
/api/cloud/events/Headers
AuthorizationApi-Key $TARUVI_API_KEY
View cURL
curl --silent --show-error "$TARUVI_SITE_URL/api/cloud/events/" \
-H "Authorization: Api-Key $TARUVI_API_KEY"
200
The response's data.events is a list of names such as RECORD_CREATE.
Subscribe a function#
/api/cloud/events/EVENT_NAME/subscribe/Headers
AuthorizationApi-Key $TARUVI_API_KEYContent-Typeapplication/json
Request body
{
"function_id": "$FUNCTION_ID"
}
View cURL
curl --silent --show-error -X POST "$TARUVI_SITE_URL/api/cloud/events/EVENT_NAME/subscribe/" \
-H "Authorization: Api-Key $TARUVI_API_KEY" \
-H "Content-Type: application/json" \
--data-binary @- <<JSON
{
"function_id": "$FUNCTION_ID"
}
JSON
201
| 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#
/api/cloud/events/EVENT_NAME/unsubscribe/Headers
AuthorizationApi-Key $TARUVI_API_KEYContent-Typeapplication/json
Request body
{
"function_id": "$FUNCTION_ID"
}
View cURL
curl --silent --show-error -X POST "$TARUVI_SITE_URL/api/cloud/events/EVENT_NAME/unsubscribe/" \
-H "Authorization: Api-Key $TARUVI_API_KEY" \
-H "Content-Type: application/json" \
--data-binary @- <<JSON
{
"function_id": "$FUNCTION_ID"
}
JSON
200
This returns 200 OK when the subscription is removed. If the function wasn't
subscribed, the request returns 404 NOT_FOUND; check the subscribers list
below to confirm the current state.
List an app's subscribers#
/api/apps/APP_SLUG/events/EVENT_NAME/Headers
AuthorizationApi-Key $TARUVI_API_KEY
View cURL
curl --silent --show-error "$TARUVI_SITE_URL/api/apps/APP_SLUG/events/EVENT_NAME/" \
-H "Authorization: Api-Key $TARUVI_API_KEY"
200
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.
Before you enable Events in production, also test event subscription access to confirm that only organization owners and admins can change subscriptions.