Skip to main content
PATCH
/
v2
/
topics
/
{topicKey}
/
subscriptions
/
{identifier}
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();

$updateTopicSubscriptionRequestDto = new Components\UpdateTopicSubscriptionRequestDto(
    name: 'My Subscription',
    preferences: [
        new Components\WorkflowPreferenceRequestDto(
            condition: [
                '===' => [
                    [
                        'var' => 'tier',
                    ],
                    'premium',
                ],
            ],
            workflowId: 'workflow-123',
        ),
    ],
);

$response = $sdk->topics->subscriptions->update(
    topicKey: '<value>',
    identifier: '<value>',
    updateTopicSubscriptionRequestDto: $updateTopicSubscriptionRequestDto

);

if ($response->subscriptionResponseDto !== null) {
    // handle response
}
{
  "_id": "64f5e95d3d7946d80d0cb679",
  "topic": {
    "_id": "64f5e95d3d7946d80d0cb677",
    "key": "product-updates",
    "name": "Product Updates"
  },
  "subscriber": {
    "_id": "64da692e9a94fb2e6449ad07",
    "subscriberId": "user-123",
    "avatar": "https://example.com/avatar.png",
    "firstName": "John",
    "lastName": "Doe",
    "email": "john@example.com"
  },
  "createdAt": "2025-04-24T05:40:21Z",
  "updatedAt": "2025-04-24T05:40:21Z",
  "identifier": "tk=product-updates:si=subscriber-123",
  "name": "My Subscription",
  "preferences": [
    {
      "subscriptionId": "64f5e95d3d7946d80d0cb679",
      "enabled": true,
      "workflow": {
        "id": "64a1b2c3d4e5f6g7h8i9j0k1",
        "identifier": "welcome-email",
        "name": "Welcome Email Workflow",
        "critical": false,
        "tags": [
          "user-onboarding",
          "email"
        ],
        "data": {
          "category": "onboarding",
          "priority": "high"
        }
      },
      "condition": {
        "and": [
          {
            "===": [
              {
                "var": "tier"
              },
              "premium"
            ]
          }
        ]
      }
    }
  ],
  "contextKeys": [
    "tenant:org-a",
    "project:proj-123"
  ]
}

Authorizations

Authorization
string
header
required

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

Headers

idempotency-key
string

A header for idempotency purposes

Path Parameters

topicKey
string
required

The key identifier of the topic

identifier
string
required

The unique identifier of the subscription

Body

application/json
name
string

The name of the subscription

Example:

"My Subscription"

preferences
string · object · object[]

The preferences of the topic. Can be a simple workflow ID string, workflow preference object, or group filter object

Example:
[
{
"workflowId": "workflow-123",
"condition": { "===": [{ "var": "tier" }, "premium"] }
}
]

Response

OK

_id
string
required

The unique identifier of the subscription

Example:

"64f5e95d3d7946d80d0cb679"

topic
object
required

The topic information

subscriber
object
required

The subscriber information

createdAt
string
required

The creation date of the subscription

Example:

"2025-04-24T05:40:21Z"

updatedAt
string
required

The last update date of the subscription

Example:

"2025-04-24T05:40:21Z"

identifier
string

The identifier of the subscription

Example:

"tk=product-updates:si=subscriber-123"

name
string

The name of the subscription

Example:

"My Subscription"

preferences
object[]

The preferences for workflows in this subscription

contextKeys
string[]

Context keys that scope this subscription (e.g., tenant:org-a, project:proj-123)

Example:
["tenant:org-a", "project:proj-123"]