Skip to main content
POST
/
v2
/
subscribers
PHP
declare(strict_types=1);

require 'vendor/autoload.php';

use novu;
use novu\Models\Components;

$sdk = novu\Novu::builder()
    ->setSecurity(
        'YOUR_SECRET_KEY_HERE'
    )
    ->build();

$createSubscriberRequestDto = new Components\CreateSubscriberRequestDto(
    firstName: 'John',
    lastName: 'Doe',
    email: 'john.doe@example.com',
    phone: '+1234567890',
    avatar: 'https://example.com/avatar.jpg',
    locale: 'en-US',
    timezone: 'America/New_York',
    subscriberId: '<id>',
);

$response = $sdk->subscribers->create(
    createSubscriberRequestDto: $createSubscriberRequestDto
);

if ($response->subscriberResponseDto !== null) {
    // handle response
}
{
  "subscriberId": "<string>",
  "_organizationId": "<string>",
  "_environmentId": "<string>",
  "deleted": true,
  "createdAt": "<string>",
  "updatedAt": "<string>",
  "_id": "<string>",
  "firstName": "<string>",
  "lastName": "<string>",
  "email": "<string>",
  "phone": "<string>",
  "avatar": "<string>",
  "locale": "<string>",
  "channels": [
    {
      "credentials": {
        "webhookUrl": "https://example.com/webhook",
        "channel": "general",
        "deviceTokens": [
          "token1",
          "token2",
          "token3"
        ],
        "alertUid": "12345-abcde",
        "title": "Critical Alert",
        "imageUrl": "https://example.com/image.png",
        "state": "resolved",
        "externalUrl": "https://example.com/details"
      },
      "_integrationId": "<string>",
      "integrationIdentifier": "<string>"
    }
  ],
  "topics": [
    "<string>"
  ],
  "isOnline": true,
  "lastOnlineAt": "<string>",
  "__v": 123,
  "data": {},
  "timezone": "<string>"
}

Authorizations

Authorization
string
header
required

API key authentication. Allowed headers-- "Authorization: ApiKey <novu_secret_key>".

Headers

idempotency-key
string

A header for idempotency purposes

Query Parameters

failIfExists
boolean

If true, the request will fail if a subscriber with the same subscriberId already exists

Body

application/json
subscriberId
string
required

Unique identifier of the subscriber

firstName
string | null

First name of the subscriber

Example:

"John"

lastName
string | null

Last name of the subscriber

Example:

"Doe"

email
string | null

Email address of the subscriber

Example:

"john.doe@example.com"

phone
string | null

Phone number of the subscriber

Example:

"+1234567890"

avatar
string | null

Avatar URL or identifier

Example:

"https://example.com/avatar.jpg"

locale
string | null

Locale of the subscriber

Example:

"en-US"

timezone
string | null

Timezone of the subscriber

Example:

"America/New_York"

data
object

Additional custom data associated with the subscriber

Response

Created

subscriberId
string
required

The identifier used to create this subscriber, which typically corresponds to the user ID in your system.

_organizationId
string
required

The unique identifier of the organization to which the subscriber belongs.

_environmentId
string
required

The unique identifier of the environment associated with this subscriber.

deleted
boolean
required

Indicates whether the subscriber has been deleted.

createdAt
string
required

The timestamp indicating when the subscriber was created, in ISO 8601 format.

updatedAt
string
required

The timestamp indicating when the subscriber was last updated, in ISO 8601 format.

_id
string

The internal ID generated by Novu for your subscriber. This ID does not match the subscriberId used in your queries. Refer to subscriberId for that identifier.

firstName
string | null

The first name of the subscriber.

lastName
string | null

The last name of the subscriber.

email
string | null

The email address of the subscriber.

phone
string | null

The phone number of the subscriber.

avatar
string | null

The URL of the subscriber's avatar image.

locale
string | null

The locale setting of the subscriber, indicating their preferred language or region.

channels
object[]

An array of channel settings associated with the subscriber.

topics
string[]
deprecated

An array of topics that the subscriber is subscribed to.

isOnline
boolean | null

Indicates whether the subscriber is currently online.

lastOnlineAt
string | null

The timestamp indicating when the subscriber was last online, in ISO 8601 format.

__v
number

The version of the subscriber document.

data
object

Additional custom data for the subscriber

timezone
string | null

Timezone of the subscriber