NotifyAdminAPIClient and provide methods for managing services, users, notifications, and other resources.
Base Client
NotifyAdminAPIClient
Base class for all Notify API clients. Handles authentication, request headers, and common HTTP operations. Location:app/notify_client/__init__.py
- Automatic authentication with bearer tokens
- Request tracking with user IDs in headers
- Integration with Flask request context
Service Management
ServiceAPIClient
Manages services, templates, guest lists, and service configuration. Location:app/notify_client/service_api_client.py
Key Methods
Creates a new service with specified limits and configuration.Parameters:
service_name(str): Service nameorganisation_type(str): Type of organisationemail_message_limit(int): Daily email limitinternational_sms_message_limit(int): Daily international SMS limitsms_message_limit(int): Daily SMS limitletter_message_limit(int): Daily letter limitrestricted(bool): Whether service is in trial modeuser_id(str): ID of user creating the service
Retrieves service details. Results are cached.Parameters:
service_id(str): Service ID
Updates service configuration. Only specific attributes are allowed.Allowed attributes: active, billing_contact_email_addresses, billing_contact_names, billing_reference, confirmed_email_sender_name, contact_link, email_branding, free_sms_fragment_limit, go_live_at, letter_branding, letter_contact_block, email_message_limit, name, notes, organisation_type, permissions, prefix_sms, rate_limit, reply_to_email_address, restricted, sms_sender, volume_email, volume_letter, volume_sms
Gets notification statistics for a service.Parameters:
service_id(str): Service IDlimit_days(int, optional): Limit to notifications from last N days
User Management
UserApiClient
Manages user accounts, authentication, permissions, and WebAuthn credentials. Location:app/notify_client/user_api_client.py
Key Methods
Creates a new user account.Parameters:
name(str): Full nameemail_address(str): Email addressmobile_number(str): Mobile number for SMS authpassword(str): User passwordauth_type(str): Authentication method (“sms_auth”, “email_auth”, “webauthn_auth”)
Updates specific user attributes.Allowed attributes: name, email_address, mobile_number, auth_type, updated_by, current_session_id, email_access_validated_at, take_part_in_research, receives_new_features_email, platform_adminNote: platform_admin can only be set to False for security
Sends a verification code via SMS or email.Parameters:
user_id(str): User IDcode_type(str): “sms” or “email”to(str): Phone number or email addressnext_string(str, optional): URL to redirect to after verification
Adds a user to a service with specific permissions.Parameters:
service_id(str): Service IDuser_id(str): User IDpermissions(list): UI permission names (converted to DB permissions internally)folder_permissions(list): List of folder IDs user can access
Notification Management
NotificationApiClient
Manages notifications, including sending, retrieving, and tracking notification status. Location:app/notify_client/notification_api_client.py
Key Methods
Retrieves notifications for a service with filtering options.Parameters:
service_id(str): Service IDjob_id(str, optional): Filter by jobtemplate_type(str, optional): “email”, “sms”, or “letter”status(str, optional): Notification statuspage(int, optional): Page numberpage_size(int, optional): Results per pagecount_pages(bool, optional): Whether to count total pageslimit_days(int, optional): Limit to last N daysto(str, optional): Filter by recipient (uses POST to avoid logging PII)
Sends a notification using a template.Parameters:
service_id(str): Service IDtemplate_id(str): Template IDrecipient(str): Email address or phone numberpersonalisation(dict): Template placeholder valuessender_id(str, optional): Sender ID to use
Job Management
JobApiClient
Manages batch notification jobs and file uploads. Location:app/notify_client/job_api_client.py
Job Statuses
TheJobApiClient defines several job status constants:
scheduled- Job is scheduled for future sendingpending- Job is queued but not yet processingin progress- Job is currently being processedfinished- Job completed successfullyfinished all notifications created- All notifications created from jobcancelled- Job was cancelledsending limits exceeded- Job exceeded service limitsready to send- Job ready to startsent to dvla- Letter job sent to DVLA
Creates a new batch notification job.Parameters:
job_id(str): Unique job IDservice_id(str): Service IDscheduled_for(str, optional): ISO datetime string for scheduled sendingcontact_list_id(str, optional): Contact list to use
Retrieves jobs for a service.Parameters:
service_id(str): Service IDlimit_days(int, optional): Only jobs from last N dayscontact_list_id(str, optional): Filter by contact liststatuses(list, optional): Filter by job statusespage(int): Page number (default: 1)
API Key Management
ApiKeyApiClient
Manages service API keys for programmatic access. Location:app/notify_client/api_key_api_client.py
Creates a new API key for a service.Parameters:
service_id(str): Service IDkey_name(str): Descriptive name for the keykey_type(str): Type of key (“normal”, “team”, “test”)
Caching
Many API client methods use Redis caching to improve performance:@cache.set("cache-key")- Caches the result@cache.delete("cache-key")- Invalidates cache on update@cache.delete_by_pattern("pattern*")- Invalidates multiple cache entries
Error Handling
All clients inherit error handling fromBaseAPIClient. Common exceptions:
HTTPError- Raised for HTTP error responses (4xx, 5xx)InviteTokenError- Raised for invalid invite tokens