Create a topic
Creates a new topic if it does not exist, or updates an existing topic if it already exists. Use ?failIfExists=true to prevent updates.
import { Novu } from "@novu/api";
const novu = new Novu({
secretKey: "YOUR_SECRET_KEY_HERE",
});
async function run() {
const result = await novu.topics.create({
key: "task:12345",
name: "Task Title",
});
console.log(result);
}
run();using Novu;
using Novu.Models.Components;
var sdk = new NovuSDK(secretKey: "YOUR_SECRET_KEY_HERE");
var res = await sdk.Topics.CreateAsync(createUpdateTopicRequestDto: new CreateUpdateTopicRequestDto() {
Key = "task:12345",
Name = "Task Title",
});
// 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();
$createUpdateTopicRequestDto = new Components\CreateUpdateTopicRequestDto(
key: 'task:12345',
name: 'Task Title',
);
$response = $sdk->topics->create(
createUpdateTopicRequestDto: $createUpdateTopicRequestDto
);
if ($response->topicResponseDto !== null) {
// handle response
}from novu_py import Novu
with Novu(
secret_key="YOUR_SECRET_KEY_HERE",
) as novu:
res = novu.topics.create(create_update_topic_request_dto={
"key": "task:12345",
"name": "Task Title",
})
# 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.Topics.Create(ctx, components.CreateUpdateTopicRequestDto{
Key: "task:12345",
Name: v3.Pointer("Task Title"),
}, nil, nil)
if err != nil {
log.Fatal(err)
}
if res.TopicResponseDto != nil {
// handle response
}
}curl --request POST \
--url https://api.novu.co/v2/topics \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"key": "task:12345",
"name": "Task Title"
}
'const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({key: 'task:12345', name: 'Task Title'})
};
fetch('https://api.novu.co/v2/topics', 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/topics")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"key\": \"task:12345\",\n \"name\": \"Task Title\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.novu.co/v2/topics")
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 \"key\": \"task:12345\",\n \"name\": \"Task Title\"\n}"
response = http.request(request)
puts response.read_body{
"_id": "64da692e9a94fb2e6449ad06",
"key": "product-updates",
"name": "Product Updates",
"createdAt": "2023-08-15T00:00:00.000Z",
"updatedAt": "2023-08-15T00:00:00.000Z"
}{
"_id": "64da692e9a94fb2e6449ad06",
"key": "product-updates",
"name": "Product Updates",
"createdAt": "2023-08-15T00:00:00.000Z",
"updatedAt": "2023-08-15T00:00:00.000Z"
}{
"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"
}{
"_id": "64da692e9a94fb2e6449ad06",
"key": "product-updates",
"name": "Product Updates",
"createdAt": "2023-08-15T00:00:00.000Z",
"updatedAt": "2023-08-15T00:00:00.000Z"
}{
"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
Query Parameters
If true, the request will fail if a topic with the same key already exists
Body
The unique key identifier for the topic. The key must contain only alphanumeric characters (a-z, A-Z, 0-9), hyphens (-), underscores (_), colons (:), or be a valid email address.
1 - 100"task:12345"
The display name for the topic
100"Task Title"
Response
OK
The identifier of the topic
"64da692e9a94fb2e6449ad06"
The unique key of the topic
"product-updates"
The name of the topic
"Product Updates"
The date the topic was created
"2023-08-15T00:00:00.000Z"
The date the topic was last updated
"2023-08-15T00:00:00.000Z"
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.topics.create({
key: "task:12345",
name: "Task Title",
});
console.log(result);
}
run();using Novu;
using Novu.Models.Components;
var sdk = new NovuSDK(secretKey: "YOUR_SECRET_KEY_HERE");
var res = await sdk.Topics.CreateAsync(createUpdateTopicRequestDto: new CreateUpdateTopicRequestDto() {
Key = "task:12345",
Name = "Task Title",
});
// 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();
$createUpdateTopicRequestDto = new Components\CreateUpdateTopicRequestDto(
key: 'task:12345',
name: 'Task Title',
);
$response = $sdk->topics->create(
createUpdateTopicRequestDto: $createUpdateTopicRequestDto
);
if ($response->topicResponseDto !== null) {
// handle response
}from novu_py import Novu
with Novu(
secret_key="YOUR_SECRET_KEY_HERE",
) as novu:
res = novu.topics.create(create_update_topic_request_dto={
"key": "task:12345",
"name": "Task Title",
})
# 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.Topics.Create(ctx, components.CreateUpdateTopicRequestDto{
Key: "task:12345",
Name: v3.Pointer("Task Title"),
}, nil, nil)
if err != nil {
log.Fatal(err)
}
if res.TopicResponseDto != nil {
// handle response
}
}curl --request POST \
--url https://api.novu.co/v2/topics \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"key": "task:12345",
"name": "Task Title"
}
'const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({key: 'task:12345', name: 'Task Title'})
};
fetch('https://api.novu.co/v2/topics', 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/topics")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"key\": \"task:12345\",\n \"name\": \"Task Title\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.novu.co/v2/topics")
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 \"key\": \"task:12345\",\n \"name\": \"Task Title\"\n}"
response = http.request(request)
puts response.read_body{
"_id": "64da692e9a94fb2e6449ad06",
"key": "product-updates",
"name": "Product Updates",
"createdAt": "2023-08-15T00:00:00.000Z",
"updatedAt": "2023-08-15T00:00:00.000Z"
}{
"_id": "64da692e9a94fb2e6449ad06",
"key": "product-updates",
"name": "Product Updates",
"createdAt": "2023-08-15T00:00:00.000Z",
"updatedAt": "2023-08-15T00:00:00.000Z"
}{
"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"
}{
"_id": "64da692e9a94fb2e6449ad06",
"key": "product-updates",
"name": "Product Updates",
"createdAt": "2023-08-15T00:00:00.000Z",
"updatedAt": "2023-08-15T00:00:00.000Z"
}{
"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."