novuhq / novu
Requires
- php: ^8.2
- brick/date-time: ^0.7.0
- brick/math: ^0.12.1
- galbar/jsonpath: ^3.0
- guzzlehttp/guzzle: ^7.0
- phpdocumentor/type-resolver: ^1.8
- speakeasy/serializer: ^4.0.3
Requires (Dev)
- laravel/pint: ^1.21.2
- phpstan/phpstan: ^2.1.0
- phpunit/phpunit: ^10
- roave/security-advisories: dev-latest
This package is auto-updated.
Last update: 2025-05-13 19:12:58 UTC
README

The <Inbox /> infrastructure for modern products
The notification platform that turns complex multi-channel delivery into a single component. Built for developers, designed for growth, powered by open source.Novu PHP SDK
The PHP Novu SDK and package provides a fluent and expressive interface for interacting with Novu's API and managing notifications.
Developer-friendly & type-safe Php SDK specifically catered to leverage novuhq/novu API.
Important
This SDK is not yet ready for production use. To complete setup please follow the steps outlined in your workspace. Delete this section before > publishing to a package manager.
Summary
Novu API: Novu REST API. Please see https://docs.novu.co/api-reference for more details.
For more information about the API: Novu Documentation
Table of Contents
SDK Installation
The SDK relies on Composer to manage its dependencies.
To install the SDK and add it as a dependency to an existing composer.json
file:
composer require "novuhq/novu"
SDK Example Usage
Trigger Notification Event
declare(strict_types=1); require 'vendor/autoload.php'; use novu; use novu\Models\Components; $sdk = novu\Novu::builder() ->setSecurity( 'YOUR_SECRET_KEY_HERE' ) ->build(); $triggerEventRequestDto = new Components\TriggerEventRequestDto( workflowId: 'workflow_identifier', payload: [ 'comment_id' => 'string', 'post' => [ 'text' => 'string', ], ], overrides: new Components\Overrides(), to: new Components\SubscriberPayloadDto( subscriberId: '<id>', ), ); $response = $sdk->trigger( triggerEventRequestDto: $triggerEventRequestDto, idempotencyKey: '<value>' ); if ($response->triggerEventResponseDto !== null) { // handle response }
Cancel Triggered Event
declare(strict_types=1); require 'vendor/autoload.php'; use novu; $sdk = novu\Novu::builder() ->setSecurity( 'YOUR_SECRET_KEY_HERE' ) ->build(); $response = $sdk->cancel( transactionId: '<id>', idempotencyKey: '<value>' ); if ($response->boolean !== null) { // handle response }
Broadcast Event to All
declare(strict_types=1); require 'vendor/autoload.php'; use novu; use novu\Models\Components; $sdk = novu\Novu::builder() ->setSecurity( 'YOUR_SECRET_KEY_HERE' ) ->build(); $triggerEventToAllRequestDto = new Components\TriggerEventToAllRequestDto( name: '<value>', payload: [ 'comment_id' => 'string', 'post' => [ 'text' => 'string', ], ], overrides: new Components\TriggerEventToAllRequestDtoOverrides( additionalProperties: [ 'fcm' => [ 'data' => [ 'key' => 'value', ], ], ], ), ); $response = $sdk->triggerBroadcast( triggerEventToAllRequestDto: $triggerEventToAllRequestDto, idempotencyKey: '<value>' ); if ($response->triggerEventResponseDto !== null) { // handle response }
Trigger Notification Events in Bulk
declare(strict_types=1); require 'vendor/autoload.php'; use novu; use novu\Models\Components; $sdk = novu\Novu::builder() ->setSecurity( 'YOUR_SECRET_KEY_HERE' ) ->build(); $bulkTriggerEventDto = new Components\BulkTriggerEventDto( events: [ new Components\TriggerEventRequestDto( workflowId: 'workflow_identifier', payload: [ 'comment_id' => 'string', 'post' => [ 'text' => 'string', ], ], overrides: new Components\Overrides(), to: new Components\TopicPayloadDto( topicKey: '<value>', type: Components\TriggerRecipientsTypeEnum::Topic, ), ), ], ); $response = $sdk->triggerBulk( bulkTriggerEventDto: $bulkTriggerEventDto, idempotencyKey: '<value>' ); if ($response->triggerEventResponseDtos !== null) { // handle response }
Authentication
Per-Client Security Schemes
This SDK supports the following security scheme globally:
Name | Type | Scheme |
---|---|---|
secretKey |
apiKey | API key |
To authenticate with the API the secretKey
parameter must be set when initializing the SDK. For example:
declare(strict_types=1); require 'vendor/autoload.php'; use novu; use novu\Models\Components; $sdk = novu\Novu::builder() ->setSecurity( 'YOUR_SECRET_KEY_HERE' ) ->build(); $triggerEventRequestDto = new Components\TriggerEventRequestDto( workflowId: 'workflow_identifier', payload: [ 'comment_id' => 'string', 'post' => [ 'text' => 'string', ], ], overrides: new Components\Overrides(), to: new Components\SubscriberPayloadDto( subscriberId: '<id>', ), ); $response = $sdk->trigger( triggerEventRequestDto: $triggerEventRequestDto, idempotencyKey: '<value>' ); if ($response->triggerEventResponseDto !== null) { // handle response }
Available Resources and Operations
Available methods
integrations
- list - Get integrations
- create - Create integration
- update - Update integration
- delete - Delete integration
- setAsPrimary - Set integration as primary
- listActive - Get active integrations
integrations->webhooks
- getSupportStatus - Get webhook support status for provider
messages
- get - Get messages
- delete - Delete message
- deleteByTransactionId - Delete messages by transactionId
notifications
notifications->stats
- get - Get notification statistics
notificationsStats
- getGraph - Get notification graph statistics
Novu SDK
- trigger - Trigger event
- cancel - Cancel triggered event
- triggerBroadcast - Broadcast event to all
- triggerBulk - Bulk trigger event
subscribers
- search - Search for subscribers
- create - Create subscriber
- get - Get subscriber
- patch - Patch subscriber
- delete - Delete subscriber
- list - Get subscribers
- update - Upsert subscriber
- createBulk - Bulk create subscribers
- updatePreferences - Update subscriber global or workflow specific preferences
- updateCredentials - Update subscriber credentials
- updateOnlineStatus - Update subscriber online status
subscribers->authentication
- handleOauthCallback - Handle providers oauth redirect
subscribers->messages
- updateAsSeen - Mark message action as seen
- markAllAs - Mark a subscriber messages as seen, read, unseen or unread
subscribers->notifications
- getFeed - Get in-app notification feed for a particular subscriber
subscribers->topics
- list - List topics a subscriber is subscribed to
subscribersAuthentication
- chatAccessOauth - Handle chat oauth
subscribersCredentials
- append - Modify subscriber credentials
- deleteProvider - Delete subscriber credentials by providerId
subscribersMessages
- markAll - Marks all the subscriber messages as read, unread, seen or unseen.
subscribersNotifications
- getUnseenCount - Get the unseen in-app notifications count for subscribers feed
subscribersPreferences
- list - Get subscriber preferences
topics
- list - Get topics list
- create - Create or update a topic
- get - Get topic by key
- update - Update topic by key
- delete - Delete topic by key
topics->subscriptions
- list - List topic subscriptions
- create - Create topic subscriptions, if the topic does not exist, it will be created.
- delete - Delete topic subscriptions
topicsSubscribers
- check - Check topic subscriber
Pagination
Some of the endpoints in this SDK support pagination. To use pagination, you make your SDK calls as usual, but the
returned object will be a Generator
instead of an individual response.
Working with generators is as simple as iterating over the responses in a foreach
loop, and you can see an example below:
declare(strict_types=1); require 'vendor/autoload.php'; use novu; $sdk = novu\Novu::builder() ->setSecurity( 'YOUR_SECRET_KEY_HERE' ) ->build(); $responses = $sdk->subscribers->list( page: 7685.78, limit: 10, idempotencyKey: '<value>' ); foreach ($responses as $response) { if ($response->statusCode === 200) { // handle response } }
Retries
Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.
To change the default retry strategy for a single API call, simply provide an Options
object built with a RetryConfig
object to the call:
declare(strict_types=1); require 'vendor/autoload.php'; use novu; use novu\Models\Components; use novu\Utils\Retry; $sdk = novu\Novu::builder() ->setSecurity( 'YOUR_SECRET_KEY_HERE' ) ->build(); $triggerEventRequestDto = new Components\TriggerEventRequestDto( workflowId: 'workflow_identifier', payload: [ 'comment_id' => 'string', 'post' => [ 'text' => 'string', ], ], overrides: new Components\Overrides(), to: new Components\SubscriberPayloadDto( subscriberId: '<id>', ), ); $response = $sdk->trigger( triggerEventRequestDto: $triggerEventRequestDto, idempotencyKey: '<value>', options: Utils\Options->builder()->setRetryConfig( new Retry\RetryConfigBackoff( initialInterval: 1, maxInterval: 50, exponent: 1.1, maxElapsedTime: 100, retryConnectionErrors: false, ))->build() ); if ($response->triggerEventResponseDto !== null) { // handle response }
If you'd like to override the default retry strategy for all operations that support retries, you can pass a RetryConfig
object to the SDKBuilder->setRetryConfig
function when initializing the SDK:
declare(strict_types=1); require 'vendor/autoload.php'; use novu; use novu\Models\Components; use novu\Utils\Retry; $sdk = novu\Novu::builder() ->setRetryConfig( new Retry\RetryConfigBackoff( initialInterval: 1, maxInterval: 50, exponent: 1.1, maxElapsedTime: 100, retryConnectionErrors: false, ) ) ->setSecurity( 'YOUR_SECRET_KEY_HERE' ) ->build(); $triggerEventRequestDto = new Components\TriggerEventRequestDto( workflowId: 'workflow_identifier', payload: [ 'comment_id' => 'string', 'post' => [ 'text' => 'string', ], ], overrides: new Components\Overrides(), to: new Components\SubscriberPayloadDto( subscriberId: '<id>', ), ); $response = $sdk->trigger( triggerEventRequestDto: $triggerEventRequestDto, idempotencyKey: '<value>' ); if ($response->triggerEventResponseDto !== null) { // handle response }
Error Handling
Handling errors in this SDK should largely match your expectations. All operations return a response object or throw an exception.
By default an API error will raise a Errors\APIException
exception, which has the following properties:
Property | Type | Description |
---|---|---|
$message |
string | The error message |
$statusCode |
int | The HTTP status code |
$rawResponse |
?\Psr\Http\Message\ResponseInterface | The raw HTTP response |
$body |
string | The response content |
When custom error responses are specified for an operation, the SDK may also throw their associated exception. You can refer to respective Errors tables in SDK docs for more details on possible exception types for each operation. For example, the trigger
method throws the following exceptions:
Error Type | Status Code | Content Type |
---|---|---|
Errors\ErrorDto | 414 | application/json |
Errors\ErrorDto | 400, 401, 403, 404, 405, 409, 413, 415 | application/json |
Errors\ValidationErrorDto | 422 | application/json |
Errors\ErrorDto | 500 | application/json |
Errors\APIException | 4XX, 5XX | */* |
Example
declare(strict_types=1); require 'vendor/autoload.php'; use novu; use novu\Models\Components; use novu\Models\Errors; $sdk = novu\Novu::builder() ->setSecurity( 'YOUR_SECRET_KEY_HERE' ) ->build(); try { $triggerEventRequestDto = new Components\TriggerEventRequestDto( workflowId: 'workflow_identifier', payload: [ 'comment_id' => 'string', 'post' => [ 'text' => 'string', ], ], overrides: new Components\Overrides(), to: new Components\SubscriberPayloadDto( subscriberId: '<id>', ), ); $response = $sdk->trigger( triggerEventRequestDto: $triggerEventRequestDto, idempotencyKey: '<value>' ); if ($response->triggerEventResponseDto !== null) { // handle response } } catch (Errors\ErrorDtoThrowable $e) { // handle $e->$container data throw $e; } catch (Errors\ErrorDtoThrowable $e) { // handle $e->$container data throw $e; } catch (Errors\ValidationErrorDtoThrowable $e) { // handle $e->$container data throw $e; } catch (Errors\ErrorDtoThrowable $e) { // handle $e->$container data throw $e; } catch (Errors\APIException $e) { // handle default exception throw $e; }
Server Selection
Select Server by Index
You can override the default server globally using the setServerIndex(int $serverIdx)
builder method when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers:
# | Server | Description |
---|---|---|
0 | https://api.novu.co |
|
1 | https://eu.api.novu.co |
Example
declare(strict_types=1); require 'vendor/autoload.php'; use novu; use novu\Models\Components; $sdk = novu\Novu::builder() ->setServerIndex(1) ->setSecurity( 'YOUR_SECRET_KEY_HERE' ) ->build(); $triggerEventRequestDto = new Components\TriggerEventRequestDto( workflowId: 'workflow_identifier', payload: [ 'comment_id' => 'string', 'post' => [ 'text' => 'string', ], ], overrides: new Components\Overrides(), to: new Components\SubscriberPayloadDto( subscriberId: '<id>', ), ); $response = $sdk->trigger( triggerEventRequestDto: $triggerEventRequestDto, idempotencyKey: '<value>' ); if ($response->triggerEventResponseDto !== null) { // handle response }
Override Server URL Per-Client
The default server can also be overridden globally using the setServerUrl(string $serverUrl)
builder method when initializing the SDK client instance. For example:
declare(strict_types=1); require 'vendor/autoload.php'; use novu; use novu\Models\Components; $sdk = novu\Novu::builder() ->setServerURL('https://eu.api.novu.co') ->setSecurity( 'YOUR_SECRET_KEY_HERE' ) ->build(); $triggerEventRequestDto = new Components\TriggerEventRequestDto( workflowId: 'workflow_identifier', payload: [ 'comment_id' => 'string', 'post' => [ 'text' => 'string', ], ], overrides: new Components\Overrides(), to: new Components\SubscriberPayloadDto( subscriberId: '<id>', ), ); $response = $sdk->trigger( triggerEventRequestDto: $triggerEventRequestDto, idempotencyKey: '<value>' ); if ($response->triggerEventResponseDto !== null) { // handle response }
Development
Maturity
This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.
Contributions
While we value open-source contributions to this SDK, this library is generated programmatically. Any manual changes added to internal files will be overwritten on the next generation. We look forward to hearing your feedback. Feel free to open a PR or an issue with a proof of concept and we'll do our best to include it in a future release.