Preferences
Bulk update subscriber preferences
Bulk update subscriber preferences by its unique key identifier subscriberId. This API allows updating multiple workflow preferences in a single request.
PATCH
/
v2
/
subscribers
/
{subscriberId}
/
preferences
/
bulk
TypeScript
import { Novu } from "@novu/api";
const novu = new Novu({
secretKey: "YOUR_SECRET_KEY_HERE",
});
async function run() {
const result = await novu.subscribers.preferences.bulkUpdate({
preferences: [],
context: {
"key": "org-acme",
},
}, "<id>");
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.Subscribers.Preferences.BulkUpdateAsync(
subscriberId: "<id>",
bulkUpdateSubscriberPreferencesDto: new BulkUpdateSubscriberPreferencesDto() {
Preferences = new List<BulkUpdateSubscriberPreferenceItemDto>() {},
Context = new Dictionary<string, BulkUpdateSubscriberPreferencesDtoContext>() {
{ "key", BulkUpdateSubscriberPreferencesDtoContext.CreateStr(
"org-acme"
) },
},
}
);
// 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();
$bulkUpdateSubscriberPreferencesDto = new Components\BulkUpdateSubscriberPreferencesDto(
preferences: [],
context: [
'key' => 'org-acme',
],
);
$response = $sdk->subscribers->preferences->bulkUpdate(
subscriberId: '<id>',
bulkUpdateSubscriberPreferencesDto: $bulkUpdateSubscriberPreferencesDto
);
if ($response->getPreferencesResponseDtos !== null) {
// handle response
}from novu_py import Novu
with Novu(
secret_key="YOUR_SECRET_KEY_HERE",
) as novu:
res = novu.subscribers.preferences.bulk_update(subscriber_id="<id>", bulk_update_subscriber_preferences_dto={
"preferences": [],
"context": {
"key": "org-acme",
},
})
# 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.Subscribers.Preferences.BulkUpdate(ctx, "<id>", components.BulkUpdateSubscriberPreferencesDto{
Preferences: []components.BulkUpdateSubscriberPreferenceItemDto{},
Context: map[string]components.BulkUpdateSubscriberPreferencesDtoContext{
"key": components.CreateBulkUpdateSubscriberPreferencesDtoContextStr(
"org-acme",
),
},
}, nil)
if err != nil {
log.Fatal(err)
}
if res.GetPreferencesResponseDtos != nil {
// handle response
}
}curl --request PATCH \
--url https://api.novu.co/v2/subscribers/{subscriberId}/preferences/bulk \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"preferences": [
{
"channels": {
"email": true,
"sms": true,
"in_app": true,
"push": true,
"chat": true
},
"workflowId": "<string>"
}
],
"context": {}
}
'const options = {
method: 'PATCH',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
preferences: [
{
channels: {email: true, sms: true, in_app: true, push: true, chat: true},
workflowId: '<string>'
}
],
context: {}
})
};
fetch('https://api.novu.co/v2/subscribers/{subscriberId}/preferences/bulk', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));HttpResponse<String> response = Unirest.patch("https://api.novu.co/v2/subscribers/{subscriberId}/preferences/bulk")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"preferences\": [\n {\n \"channels\": {\n \"email\": true,\n \"sms\": true,\n \"in_app\": true,\n \"push\": true,\n \"chat\": true\n },\n \"workflowId\": \"<string>\"\n }\n ],\n \"context\": {}\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.novu.co/v2/subscribers/{subscriberId}/preferences/bulk")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Patch.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"preferences\": [\n {\n \"channels\": {\n \"email\": true,\n \"sms\": true,\n \"in_app\": true,\n \"push\": true,\n \"chat\": true\n },\n \"workflowId\": \"<string>\"\n }\n ],\n \"context\": {}\n}"
response = http.request(request)
puts response.read_body[
{
"enabled": true,
"channels": {
"email": true,
"sms": false,
"in_app": true,
"chat": false,
"push": true
},
"workflow": {
"id": "64a1b2c3d4e5f6g7h8i9j0k1",
"identifier": "welcome-email",
"name": "Welcome Email Workflow",
"critical": false,
"tags": [
"user-onboarding",
"email"
],
"data": {
"category": "onboarding",
"priority": "high"
}
},
"condition": {}
}
]{
"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
Path Parameters
The identifier of the subscriber
Body
application/json
Response
OK
The level of the preference (global or template)
Available options:
global, template Whether the preference is enabled
Example:
true
Channel-specific preference settings
Show child attributes
Show child attributes
Workflow information if this is a template-level preference
Show child attributes
Show child attributes
Condition using JSON Logic rules
Was this page helpful?
⌘I
TypeScript
import { Novu } from "@novu/api";
const novu = new Novu({
secretKey: "YOUR_SECRET_KEY_HERE",
});
async function run() {
const result = await novu.subscribers.preferences.bulkUpdate({
preferences: [],
context: {
"key": "org-acme",
},
}, "<id>");
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.Subscribers.Preferences.BulkUpdateAsync(
subscriberId: "<id>",
bulkUpdateSubscriberPreferencesDto: new BulkUpdateSubscriberPreferencesDto() {
Preferences = new List<BulkUpdateSubscriberPreferenceItemDto>() {},
Context = new Dictionary<string, BulkUpdateSubscriberPreferencesDtoContext>() {
{ "key", BulkUpdateSubscriberPreferencesDtoContext.CreateStr(
"org-acme"
) },
},
}
);
// 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();
$bulkUpdateSubscriberPreferencesDto = new Components\BulkUpdateSubscriberPreferencesDto(
preferences: [],
context: [
'key' => 'org-acme',
],
);
$response = $sdk->subscribers->preferences->bulkUpdate(
subscriberId: '<id>',
bulkUpdateSubscriberPreferencesDto: $bulkUpdateSubscriberPreferencesDto
);
if ($response->getPreferencesResponseDtos !== null) {
// handle response
}from novu_py import Novu
with Novu(
secret_key="YOUR_SECRET_KEY_HERE",
) as novu:
res = novu.subscribers.preferences.bulk_update(subscriber_id="<id>", bulk_update_subscriber_preferences_dto={
"preferences": [],
"context": {
"key": "org-acme",
},
})
# 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.Subscribers.Preferences.BulkUpdate(ctx, "<id>", components.BulkUpdateSubscriberPreferencesDto{
Preferences: []components.BulkUpdateSubscriberPreferenceItemDto{},
Context: map[string]components.BulkUpdateSubscriberPreferencesDtoContext{
"key": components.CreateBulkUpdateSubscriberPreferencesDtoContextStr(
"org-acme",
),
},
}, nil)
if err != nil {
log.Fatal(err)
}
if res.GetPreferencesResponseDtos != nil {
// handle response
}
}curl --request PATCH \
--url https://api.novu.co/v2/subscribers/{subscriberId}/preferences/bulk \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"preferences": [
{
"channels": {
"email": true,
"sms": true,
"in_app": true,
"push": true,
"chat": true
},
"workflowId": "<string>"
}
],
"context": {}
}
'const options = {
method: 'PATCH',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
preferences: [
{
channels: {email: true, sms: true, in_app: true, push: true, chat: true},
workflowId: '<string>'
}
],
context: {}
})
};
fetch('https://api.novu.co/v2/subscribers/{subscriberId}/preferences/bulk', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));HttpResponse<String> response = Unirest.patch("https://api.novu.co/v2/subscribers/{subscriberId}/preferences/bulk")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"preferences\": [\n {\n \"channels\": {\n \"email\": true,\n \"sms\": true,\n \"in_app\": true,\n \"push\": true,\n \"chat\": true\n },\n \"workflowId\": \"<string>\"\n }\n ],\n \"context\": {}\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.novu.co/v2/subscribers/{subscriberId}/preferences/bulk")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Patch.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"preferences\": [\n {\n \"channels\": {\n \"email\": true,\n \"sms\": true,\n \"in_app\": true,\n \"push\": true,\n \"chat\": true\n },\n \"workflowId\": \"<string>\"\n }\n ],\n \"context\": {}\n}"
response = http.request(request)
puts response.read_body[
{
"enabled": true,
"channels": {
"email": true,
"sms": false,
"in_app": true,
"chat": false,
"push": true
},
"workflow": {
"id": "64a1b2c3d4e5f6g7h8i9j0k1",
"identifier": "welcome-email",
"name": "Welcome Email Workflow",
"critical": false,
"tags": [
"user-onboarding",
"email"
],
"data": {
"category": "onboarding",
"priority": "high"
}
},
"condition": {}
}
]{
"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."