Skip to main content
POST
/
v2
/
contexts
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();

$createContextRequestDto = new Components\CreateContextRequestDto(
    type: 'tenant',
    id: 'org-acme',
    data: [
        'tenantName' => 'Acme Corp',
        'region' => 'us-east-1',
        'settings' => [
            'theme' => 'dark',
        ],
    ],
);

$response = $sdk->contexts->create(
    createContextRequestDto: $createContextRequestDto
);

if ($response->getContextResponseDto !== null) {
    // handle response
}
{
  "type": "<string>",
  "id": "<string>",
  "data": {},
  "createdAt": "<string>",
  "updatedAt": "<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

Body

application/json
type
string
required

Context type (e.g., tenant, app, workspace). Must be lowercase alphanumeric with optional separators.

Required string length: 1 - 100
Pattern: ^[a-zA-Z0-9_-]+$
Example:

"tenant"

id
string
required

Unique identifier for this context. Must be lowercase alphanumeric with optional separators.

Required string length: 1 - 100
Pattern: ^[a-zA-Z0-9_-]+$
Example:

"org-acme"

data
object

Optional custom data to associate with this context.

Example:
{
"tenantName": "Acme Corp",
"region": "us-east-1",
"settings": { "theme": "dark" }
}

Response

Created

type
string
required

Context type (e.g., tenant, app, workspace)

id
string
required

Unique identifier for this context

data
object
required

Custom data associated with this context

createdAt
string
required

Creation timestamp

updatedAt
string
required

Last update timestamp