Overview
The Events API provides endpoints for creating audit trail events in the GOV.UK Notify system. Events are used for tracking system activities, user actions, and important state changes. Base URL:/events
Event Model
Events have the following structure:id(UUID) - Unique event identifierevent_type(string) - Type of event being loggedcreated_at(datetime) - When the event was createddata(JSON) - Event-specific data payload
Create Event
Endpoint:POST /events
Create a new event in the system.
Request Body
event_type(string, required) - Type of event (e.g., “api_key.created”, “service.updated”, “notification.sent”)data(object, required) - JSON object containing event-specific datacreated_at(datetime, optional) - Event creation timestamp (defaults to current time)
Response
Status:201 Created
Common Event Types
While the API accepts any event type string, common patterns include:Service Events
service.created- New service registeredservice.updated- Service configuration changedservice.deleted- Service removed
API Key Events
api_key.created- New API key generatedapi_key.revoked- API key deactivatedapi_key.expired- API key expired
Template Events
template.created- New template createdtemplate.updated- Template modifiedtemplate.deleted- Template archived
User Events
user.invited- User invitation sentuser.joined- User accepted invitationuser.removed- User removed from service
Notification Events
notification.sent- Notification dispatchednotification.delivered- Delivery confirmednotification.failed- Delivery failure
Event Data Payload
Thedata field is a flexible JSON object that can contain any relevant information for the event. Common fields include:
Usage Examples
Log Service Creation
Log Template Update
Log Failed Notification
Implementation Notes
Storage
- Events are stored in the
eventstable with indexedevent_typefor efficient querying - The
datafield uses PostgreSQL’s JSON type for flexible storage - Events are immutable once created (no update or delete endpoints)
Performance
- Event creation is asynchronous and doesn’t block main operations
- Consider batching events for high-volume operations
- The
created_atfield is indexed for time-based queries
Data Retention
- Events are retained according to the service’s data retention policy
- Historical events provide an audit trail for compliance
Source Code References
- Endpoints:
/home/daytona/workspace/source/app/events/rest.py - Schema:
/home/daytona/workspace/source/app/schemas.py:718-723 - Model:
/home/daytona/workspace/source/app/models.py:2154 - DAO operations:
/home/daytona/workspace/source/app/dao/events_dao.py