Create a context
Create a new context with the specified type, id, and data. Returns 409 if context already exists. type and id are required fields, data is optional, if the context already exists, it returns the 409 response
import { Novu } from "@novu/api";
const novu = new Novu({
secretKey: "YOUR_SECRET_KEY_HERE",
});
async function run() {
const result = await novu.contexts.create({
type: "tenant",
id: "org-acme",
data: {
"tenantName": "Acme Corp",
"region": "us-east-1",
"settings": {
"theme": "dark",
},
},
bridgeUrl: "https://tenant-acme.example.com/api/novu",
});
console.log(result);
}
run();using Novu;
using Novu.Models.Components;
using System.Collections.Generic;
var sdk = new NovuSDK(secretKey: "YOUR_SECRET_KEY_HERE");
var res = await sdk.Contexts.CreateAsync(createContextRequestDto: new CreateContextRequestDto() {
Type = "tenant",
Id = "org-acme",
Data = new Dictionary<string, object>() {
{ "tenantName", "Acme Corp" },
{ "region", "us-east-1" },
{ "settings", new Dictionary<string, object>() {
{ "theme", "dark" },
} },
},
});
// handle responsedeclare(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
}from novu_py import Novu
with Novu(
secret_key="YOUR_SECRET_KEY_HERE",
) as novu:
res = novu.contexts.create(create_context_request_dto={
"type": "tenant",
"id": "org-acme",
"data": {
"tenantName": "Acme Corp",
"region": "us-east-1",
"settings": {
"theme": "dark",
},
},
})
# Handle response
print(res)package main
import(
"context"
"github.com/novuhq/novu-go/v3"
"github.com/novuhq/novu-go/v3/models/components"
"log"
)
func main() {
ctx := context.Background()
s := v3.New(
v3.WithSecurity("YOUR_SECRET_KEY_HERE"),
)
res, err := s.Contexts.Create(ctx, components.CreateContextRequestDto{
Type: "tenant",
ID: "org-acme",
Data: map[string]any{
"tenantName": "Acme Corp",
"region": "us-east-1",
"settings": map[string]any{
"theme": "dark",
},
},
}, nil)
if err != nil {
log.Fatal(err)
}
if res.GetContextResponseDto != nil {
// handle response
}
}curl --request POST \
--url https://api.novu.co/v2/contexts \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"type": "tenant",
"id": "org-acme",
"data": {
"tenantName": "Acme Corp",
"region": "us-east-1",
"settings": {
"theme": "dark"
}
},
"bridgeUrl": "https://tenant-acme.example.com/api/novu"
}
'const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
type: 'tenant',
id: 'org-acme',
data: {tenantName: 'Acme Corp', region: 'us-east-1', settings: {theme: 'dark'}},
bridgeUrl: 'https://tenant-acme.example.com/api/novu'
})
};
fetch('https://api.novu.co/v2/contexts', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));HttpResponse<String> response = Unirest.post("https://api.novu.co/v2/contexts")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"type\": \"tenant\",\n \"id\": \"org-acme\",\n \"data\": {\n \"tenantName\": \"Acme Corp\",\n \"region\": \"us-east-1\",\n \"settings\": {\n \"theme\": \"dark\"\n }\n },\n \"bridgeUrl\": \"https://tenant-acme.example.com/api/novu\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.novu.co/v2/contexts")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"type\": \"tenant\",\n \"id\": \"org-acme\",\n \"data\": {\n \"tenantName\": \"Acme Corp\",\n \"region\": \"us-east-1\",\n \"settings\": {\n \"theme\": \"dark\"\n }\n },\n \"bridgeUrl\": \"https://tenant-acme.example.com/api/novu\"\n}"
response = http.request(request)
puts response.read_body{
"type": "<string>",
"id": "<string>",
"data": {},
"createdAt": "<string>",
"updatedAt": "<string>",
"bridgeUrl": "<string>"
}{
"statusCode": 404,
"timestamp": "2024-12-12T13:00:00Z",
"path": "/api/v1/resource",
"message": "xx xx xx ",
"ctx": {
"workflowId": "some_wf_id",
"stepId": "some_wf_id"
},
"errorId": "abc123"
}{
"statusCode": 404,
"timestamp": "2024-12-12T13:00:00Z",
"path": "/api/v1/resource",
"message": "xx xx xx ",
"ctx": {
"workflowId": "some_wf_id",
"stepId": "some_wf_id"
},
"errorId": "abc123"
}{
"statusCode": 404,
"timestamp": "2024-12-12T13:00:00Z",
"path": "/api/v1/resource",
"message": "xx xx xx ",
"ctx": {
"workflowId": "some_wf_id",
"stepId": "some_wf_id"
},
"errorId": "abc123"
}{
"statusCode": 404,
"timestamp": "2024-12-12T13:00:00Z",
"path": "/api/v1/resource",
"message": "xx xx xx ",
"ctx": {
"workflowId": "some_wf_id",
"stepId": "some_wf_id"
},
"errorId": "abc123"
}{
"statusCode": 404,
"timestamp": "2024-12-12T13:00:00Z",
"path": "/api/v1/resource",
"message": "xx xx xx ",
"ctx": {
"workflowId": "some_wf_id",
"stepId": "some_wf_id"
},
"errorId": "abc123"
}{
"statusCode": 404,
"timestamp": "2024-12-12T13:00:00Z",
"path": "/api/v1/resource",
"message": "xx xx xx ",
"ctx": {
"workflowId": "some_wf_id",
"stepId": "some_wf_id"
},
"errorId": "abc123"
}{
"statusCode": 404,
"timestamp": "2024-12-12T13:00:00Z",
"path": "/api/v1/resource",
"message": "xx xx xx ",
"ctx": {
"workflowId": "some_wf_id",
"stepId": "some_wf_id"
},
"errorId": "abc123"
}{
"statusCode": 404,
"timestamp": "2024-12-12T13:00:00Z",
"path": "/api/v1/resource",
"message": "xx xx xx ",
"ctx": {
"workflowId": "some_wf_id",
"stepId": "some_wf_id"
},
"errorId": "abc123"
}{
"statusCode": 404,
"timestamp": "2024-12-12T13:00:00Z",
"path": "/api/v1/resource",
"message": "xx xx xx ",
"ctx": {
"workflowId": "some_wf_id",
"stepId": "some_wf_id"
},
"errorId": "abc123"
}{
"statusCode": 404,
"timestamp": "2024-12-12T13:00:00Z",
"path": "/api/v1/resource",
"errors": {
"fieldName1": {
"messages": [
"Field is required",
"Must be a valid email address"
],
"value": "invalidEmail"
},
"fieldName2": {
"messages": [
"Must be at least 18 years old"
],
"value": 17
},
"fieldName3": {
"messages": [
"Must be a boolean value"
],
"value": true
},
"fieldName4": {
"messages": [
"Must be a valid object"
],
"value": {
"key": "value"
}
},
"fieldName5": {
"messages": [
"Field is missing"
],
"value": null
},
"fieldName6": {
"messages": [
"Undefined value"
]
}
},
"message": "xx xx xx ",
"ctx": {
"workflowId": "some_wf_id",
"stepId": "some_wf_id"
},
"errorId": "abc123"
}"API rate limit exceeded"{
"statusCode": 404,
"timestamp": "2024-12-12T13:00:00Z",
"path": "/api/v1/resource",
"message": "xx xx xx ",
"ctx": {
"workflowId": "some_wf_id",
"stepId": "some_wf_id"
},
"errorId": "abc123"
}"Please wait some time, then try again."Authorizations
API key authentication. Allowed headers-- "Authorization: ApiKey <novu_secret_key>".
Headers
A header for idempotency purposes
Body
Context type (e.g., tenant, app, workspace). Must be lowercase alphanumeric with optional separators.
1 - 100^[a-zA-Z0-9_-]+$"tenant"
Unique identifier for this context. Must be lowercase alphanumeric with optional separators.
1 - 100^[a-zA-Z0-9_-]+$"org-acme"
Optional custom data to associate with this context.
{
"tenantName": "Acme Corp",
"region": "us-east-1",
"settings": { "theme": "dark" }
}
Optional bridge URL override for agent connect. When an inbound agent turn resolves this context, its bridge call is routed here instead of the agent default bridge URL. Must be a publicly reachable URL.
"https://tenant-acme.example.com/api/novu"
Response
Created
Context type (e.g., tenant, app, workspace)
Unique identifier for this context
Custom data associated with this context
Creation timestamp
Last update timestamp
Bridge URL override for agent connect, if configured on this context
Was this page helpful?
import { Novu } from "@novu/api";
const novu = new Novu({
secretKey: "YOUR_SECRET_KEY_HERE",
});
async function run() {
const result = await novu.contexts.create({
type: "tenant",
id: "org-acme",
data: {
"tenantName": "Acme Corp",
"region": "us-east-1",
"settings": {
"theme": "dark",
},
},
bridgeUrl: "https://tenant-acme.example.com/api/novu",
});
console.log(result);
}
run();using Novu;
using Novu.Models.Components;
using System.Collections.Generic;
var sdk = new NovuSDK(secretKey: "YOUR_SECRET_KEY_HERE");
var res = await sdk.Contexts.CreateAsync(createContextRequestDto: new CreateContextRequestDto() {
Type = "tenant",
Id = "org-acme",
Data = new Dictionary<string, object>() {
{ "tenantName", "Acme Corp" },
{ "region", "us-east-1" },
{ "settings", new Dictionary<string, object>() {
{ "theme", "dark" },
} },
},
});
// handle responsedeclare(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
}from novu_py import Novu
with Novu(
secret_key="YOUR_SECRET_KEY_HERE",
) as novu:
res = novu.contexts.create(create_context_request_dto={
"type": "tenant",
"id": "org-acme",
"data": {
"tenantName": "Acme Corp",
"region": "us-east-1",
"settings": {
"theme": "dark",
},
},
})
# Handle response
print(res)package main
import(
"context"
"github.com/novuhq/novu-go/v3"
"github.com/novuhq/novu-go/v3/models/components"
"log"
)
func main() {
ctx := context.Background()
s := v3.New(
v3.WithSecurity("YOUR_SECRET_KEY_HERE"),
)
res, err := s.Contexts.Create(ctx, components.CreateContextRequestDto{
Type: "tenant",
ID: "org-acme",
Data: map[string]any{
"tenantName": "Acme Corp",
"region": "us-east-1",
"settings": map[string]any{
"theme": "dark",
},
},
}, nil)
if err != nil {
log.Fatal(err)
}
if res.GetContextResponseDto != nil {
// handle response
}
}curl --request POST \
--url https://api.novu.co/v2/contexts \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"type": "tenant",
"id": "org-acme",
"data": {
"tenantName": "Acme Corp",
"region": "us-east-1",
"settings": {
"theme": "dark"
}
},
"bridgeUrl": "https://tenant-acme.example.com/api/novu"
}
'const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
type: 'tenant',
id: 'org-acme',
data: {tenantName: 'Acme Corp', region: 'us-east-1', settings: {theme: 'dark'}},
bridgeUrl: 'https://tenant-acme.example.com/api/novu'
})
};
fetch('https://api.novu.co/v2/contexts', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));HttpResponse<String> response = Unirest.post("https://api.novu.co/v2/contexts")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"type\": \"tenant\",\n \"id\": \"org-acme\",\n \"data\": {\n \"tenantName\": \"Acme Corp\",\n \"region\": \"us-east-1\",\n \"settings\": {\n \"theme\": \"dark\"\n }\n },\n \"bridgeUrl\": \"https://tenant-acme.example.com/api/novu\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.novu.co/v2/contexts")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"type\": \"tenant\",\n \"id\": \"org-acme\",\n \"data\": {\n \"tenantName\": \"Acme Corp\",\n \"region\": \"us-east-1\",\n \"settings\": {\n \"theme\": \"dark\"\n }\n },\n \"bridgeUrl\": \"https://tenant-acme.example.com/api/novu\"\n}"
response = http.request(request)
puts response.read_body{
"type": "<string>",
"id": "<string>",
"data": {},
"createdAt": "<string>",
"updatedAt": "<string>",
"bridgeUrl": "<string>"
}{
"statusCode": 404,
"timestamp": "2024-12-12T13:00:00Z",
"path": "/api/v1/resource",
"message": "xx xx xx ",
"ctx": {
"workflowId": "some_wf_id",
"stepId": "some_wf_id"
},
"errorId": "abc123"
}{
"statusCode": 404,
"timestamp": "2024-12-12T13:00:00Z",
"path": "/api/v1/resource",
"message": "xx xx xx ",
"ctx": {
"workflowId": "some_wf_id",
"stepId": "some_wf_id"
},
"errorId": "abc123"
}{
"statusCode": 404,
"timestamp": "2024-12-12T13:00:00Z",
"path": "/api/v1/resource",
"message": "xx xx xx ",
"ctx": {
"workflowId": "some_wf_id",
"stepId": "some_wf_id"
},
"errorId": "abc123"
}{
"statusCode": 404,
"timestamp": "2024-12-12T13:00:00Z",
"path": "/api/v1/resource",
"message": "xx xx xx ",
"ctx": {
"workflowId": "some_wf_id",
"stepId": "some_wf_id"
},
"errorId": "abc123"
}{
"statusCode": 404,
"timestamp": "2024-12-12T13:00:00Z",
"path": "/api/v1/resource",
"message": "xx xx xx ",
"ctx": {
"workflowId": "some_wf_id",
"stepId": "some_wf_id"
},
"errorId": "abc123"
}{
"statusCode": 404,
"timestamp": "2024-12-12T13:00:00Z",
"path": "/api/v1/resource",
"message": "xx xx xx ",
"ctx": {
"workflowId": "some_wf_id",
"stepId": "some_wf_id"
},
"errorId": "abc123"
}{
"statusCode": 404,
"timestamp": "2024-12-12T13:00:00Z",
"path": "/api/v1/resource",
"message": "xx xx xx ",
"ctx": {
"workflowId": "some_wf_id",
"stepId": "some_wf_id"
},
"errorId": "abc123"
}{
"statusCode": 404,
"timestamp": "2024-12-12T13:00:00Z",
"path": "/api/v1/resource",
"message": "xx xx xx ",
"ctx": {
"workflowId": "some_wf_id",
"stepId": "some_wf_id"
},
"errorId": "abc123"
}{
"statusCode": 404,
"timestamp": "2024-12-12T13:00:00Z",
"path": "/api/v1/resource",
"message": "xx xx xx ",
"ctx": {
"workflowId": "some_wf_id",
"stepId": "some_wf_id"
},
"errorId": "abc123"
}{
"statusCode": 404,
"timestamp": "2024-12-12T13:00:00Z",
"path": "/api/v1/resource",
"errors": {
"fieldName1": {
"messages": [
"Field is required",
"Must be a valid email address"
],
"value": "invalidEmail"
},
"fieldName2": {
"messages": [
"Must be at least 18 years old"
],
"value": 17
},
"fieldName3": {
"messages": [
"Must be a boolean value"
],
"value": true
},
"fieldName4": {
"messages": [
"Must be a valid object"
],
"value": {
"key": "value"
}
},
"fieldName5": {
"messages": [
"Field is missing"
],
"value": null
},
"fieldName6": {
"messages": [
"Undefined value"
]
}
},
"message": "xx xx xx ",
"ctx": {
"workflowId": "some_wf_id",
"stepId": "some_wf_id"
},
"errorId": "abc123"
}"API rate limit exceeded"{
"statusCode": 404,
"timestamp": "2024-12-12T13:00:00Z",
"path": "/api/v1/resource",
"message": "xx xx xx ",
"ctx": {
"workflowId": "some_wf_id",
"stepId": "some_wf_id"
},
"errorId": "abc123"
}"Please wait some time, then try again."