Set up entity hooks
Setting up an entity hook involves three steps:
- Configure a notification channel.
- Create an entity hook action.
- Implement the logic to process the hook and respond.
1. Configure a notification channel
Hooks send notifications through the specialized entity feed. To receive these notifications, configure a notification channel by sending a POST request with the endpoint details.
Here's an example for an HTTP notification channel:
- CLI
- cURL
np notification channel create \
--body '{
"source": ["entity"],
"nrn": "organization=1:account=2:namespace=3",
"type": "http",
"configuration": {
"url": "https://yourdomain.com/url-you-configured"
}
}'
curl -L -X POST 'https://api.nullplatform.com/notification/channel' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d '{
"source": ["entity"],
"nrn": "organization=1:account=2:namespace=3",
"type": "http",
"configuration": {
"url": "https://yourdomain.com/url-you-configured"
}
}'
For more channel types and delivery options, see the Notifications documentation.
2. Create an entity hook action
An entity hook action declares that you want to receive notifications for a specific event on an entity type. Create an entity hook action with the event and scope you want to subscribe to:
- CLI
- cURL
np entity-hook action create \
--body '{
"nrn": "organization=1:account=2:namespace=3:application=4",
"entity": "scope",
"action": "scope:create",
"dimensions": {
"environment": "production",
"country": "us"
},
"when": "before",
"type": "hook",
"on": "create"
}'
curl -L -X POST 'https://api.nullplatform.com/entity_hook/action' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d '{
"nrn": "organization=1:account=2:namespace=3:application=4",
"entity": "scope",
"action": "scope:create",
"dimensions": {
"environment": "production",
"country": "us"
},
"when": "before",
"type": "hook",
"on": "create"
}'
Required parameters:
entity: The type of entity the hook applies to (application,scope,deployment).action: The event to subscribe to (for example,application:create,scope:write,deployment:delete).when: Whether the hook runsbeforeorafternullplatform's internal processing.type: The nature of the hook. Currently onlyhookis supported.on: The lifecycle event that triggers the hook:create,update, ordelete.
See the Entity hook API for the full parameter reference.
3. Implement hook processing
Once the hook action is configured, nullplatform starts sending notifications to your channel. Each notification has this format:
{
"id": "1180cd02-1c36-4274-8e7a-4483b87e8f2e",
"source": "entity",
"event": "scope:create",
"created_at": "2025-02-13T14:20:43.088Z",
"notification": {
"id": "550e8400-e29b-41d4-a716-446655440000",
"entity": "scope",
"entity_id": "5",
"nrn": "organization=1:account=2:namespace=3:application=4:scope=5",
"callback_url": "https://api.nullplatform.com/entity_hook/550e8400-e29b-41d4-a716-446655440000",
"type": "hook",
"when": "before",
"on": "create"
}
}
Responding to a hook
You need an ops role to perform this action.
After processing the hook, send a PATCH request to the callback_url from the notification:
{
"status": "success",
"messages": [
{
"level": "info",
"message": "Information from the hook",
"timestamp": 1740406453123
},
{
"level": "warning",
"message": "Warning report",
"timestamp": 1740406527890
},
{
"level": "error",
"message": "The hook has failed",
"timestamp": 1740406604567
}
]
}
The status field controls how nullplatform handles the outcome:
| Status | Description |
|---|---|
success | Hook logic executed successfully. The entity operation proceeds. |
failed | Operation failed entirely. The entity enters an error state. |
recoverable_failure | Partial failure. The entity remains valid but some changes may not have been applied. Relevant for update hooks. |
cancelled | Entity operation halted because conditions were not met. |
The messages array is optional. Include it to give developers visibility into the hook's execution results.