Credentials
Upsert provider credentials
Upsert credentials for a provider such as slack and FCM. providerId is required field. This API creates deviceTokens or appends to the existing ones.
PATCH
/
v1
/
subscribers
/
{subscriberId}
/
credentials
Go
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.Credentials.Append(ctx, "<id>", components.UpdateSubscriberChannelRequestDto{
ProviderID: components.ChatOrPushProviderEnumOneSignal,
Credentials: components.ChannelCredentials{
WebhookURL: v3.Pointer("https://example.com/webhook"),
Channel: v3.Pointer("general"),
DeviceTokens: []string{
"token1",
"token2",
"token3",
},
AlertUID: v3.Pointer("12345-abcde"),
Title: v3.Pointer("Critical Alert"),
ImageURL: v3.Pointer("https://example.com/image.png"),
State: v3.Pointer("resolved"),
ExternalURL: v3.Pointer("https://example.com/details"),
},
}, nil)
if err != nil {
log.Fatal(err)
}
if res.SubscriberResponseDto != nil {
// handle response
}
}import { Novu } from "@novu/api";
const novu = new Novu({
secretKey: "YOUR_SECRET_KEY_HERE",
});
async function run() {
const result = await novu.subscribers.credentials.append({
providerId: "one-signal",
credentials: {
webhookUrl: "https://example.com/webhook",
channel: "general",
deviceTokens: [
"token1",
"token2",
"token3",
],
alertUid: "12345-abcde",
title: "Critical Alert",
imageUrl: "https://example.com/image.png",
state: "resolved",
externalUrl: "https://example.com/details",
},
}, "<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.AppendCredentialsAsync(
subscriberId: "<id>",
updateSubscriberChannelRequestDto: new UpdateSubscriberChannelRequestDto() {
ProviderId = ChatOrPushProviderEnum.OneSignal,
Credentials = new ChannelCredentials() {
WebhookUrl = "https://example.com/webhook",
Channel = "general",
DeviceTokens = new List<string>() {
"token1",
"token2",
"token3",
},
AlertUid = "12345-abcde",
Title = "Critical Alert",
ImageUrl = "https://example.com/image.png",
State = "resolved",
ExternalUrl = "https://example.com/details",
},
}
);
// 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();
$updateSubscriberChannelRequestDto = new Components\UpdateSubscriberChannelRequestDto(
providerId: Components\ChatOrPushProviderEnum::OneSignal,
credentials: new Components\ChannelCredentials(
webhookUrl: 'https://example.com/webhook',
channel: 'general',
deviceTokens: [
'token1',
'token2',
'token3',
],
alertUid: '12345-abcde',
title: 'Critical Alert',
imageUrl: 'https://example.com/image.png',
state: 'resolved',
externalUrl: 'https://example.com/details',
),
);
$response = $sdk->subscribersCredentials->append(
subscriberId: '<id>',
updateSubscriberChannelRequestDto: $updateSubscriberChannelRequestDto
);
if ($response->subscriberResponseDto !== null) {
// handle response
}import novu_py
from novu_py import Novu
with Novu(
secret_key="YOUR_SECRET_KEY_HERE",
) as novu:
res = novu.subscribers.credentials.append(subscriber_id="<id>", update_subscriber_channel_request_dto={
"provider_id": novu_py.ChatOrPushProviderEnum.ONE_SIGNAL,
"credentials": {
"webhook_url": "https://example.com/webhook",
"channel": "general",
"device_tokens": [
"token1",
"token2",
"token3",
],
"alert_uid": "12345-abcde",
"title": "Critical Alert",
"image_url": "https://example.com/image.png",
"state": "resolved",
"external_url": "https://example.com/details",
},
})
# Handle response
print(res)curl --request PATCH \
--url https://api.novu.co/v1/subscribers/{subscriberId}/credentials \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"credentials": {
"webhookUrl": "https://example.com/webhook",
"channel": "general",
"deviceTokens": [
"token1",
"token2",
"token3"
],
"alertUid": "12345-abcde",
"title": "Critical Alert",
"imageUrl": "https://example.com/image.png",
"state": "resolved",
"externalUrl": "https://example.com/details"
},
"integrationIdentifier": "<string>"
}
'const options = {
method: 'PATCH',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
credentials: {
webhookUrl: 'https://example.com/webhook',
channel: 'general',
deviceTokens: ['token1', 'token2', 'token3'],
alertUid: '12345-abcde',
title: 'Critical Alert',
imageUrl: 'https://example.com/image.png',
state: 'resolved',
externalUrl: 'https://example.com/details'
},
integrationIdentifier: '<string>'
})
};
fetch('https://api.novu.co/v1/subscribers/{subscriberId}/credentials', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));HttpResponse<String> response = Unirest.patch("https://api.novu.co/v1/subscribers/{subscriberId}/credentials")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"credentials\": {\n \"webhookUrl\": \"https://example.com/webhook\",\n \"channel\": \"general\",\n \"deviceTokens\": [\n \"token1\",\n \"token2\",\n \"token3\"\n ],\n \"alertUid\": \"12345-abcde\",\n \"title\": \"Critical Alert\",\n \"imageUrl\": \"https://example.com/image.png\",\n \"state\": \"resolved\",\n \"externalUrl\": \"https://example.com/details\"\n },\n \"integrationIdentifier\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.novu.co/v1/subscribers/{subscriberId}/credentials")
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 \"credentials\": {\n \"webhookUrl\": \"https://example.com/webhook\",\n \"channel\": \"general\",\n \"deviceTokens\": [\n \"token1\",\n \"token2\",\n \"token3\"\n ],\n \"alertUid\": \"12345-abcde\",\n \"title\": \"Critical Alert\",\n \"imageUrl\": \"https://example.com/image.png\",\n \"state\": \"resolved\",\n \"externalUrl\": \"https://example.com/details\"\n },\n \"integrationIdentifier\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"subscriberId": "<string>",
"_organizationId": "<string>",
"_environmentId": "<string>",
"deleted": true,
"createdAt": "<string>",
"updatedAt": "<string>",
"_id": "<string>",
"firstName": "<string>",
"lastName": "<string>",
"email": "<string>",
"phone": "<string>",
"avatar": "<string>",
"locale": "<string>",
"channels": [
{
"providerId": "slack",
"credentials": {
"webhookUrl": "https://example.com/webhook",
"channel": "general",
"deviceTokens": [
"token1",
"token2",
"token3"
],
"alertUid": "12345-abcde",
"title": "Critical Alert",
"imageUrl": "https://example.com/image.png",
"state": "resolved",
"externalUrl": "https://example.com/details"
},
"_integrationId": "<string>",
"integrationIdentifier": "<string>"
}
],
"topics": [
"<string>"
],
"isOnline": true,
"lastOnlineAt": "<string>",
"__v": 123,
"data": {},
"timezone": "<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
Body
application/json
The provider identifier for the credentials
Available options:
slack, discord, msteams, webex-messaging, mattermost, ryver, zulip, grafana-on-call, getstream, rocket-chat, whatsapp-business, line, chat-webhook, novu-slack, telegram, sendblue, novu-web-chat, fcm, apns, expo, one-signal, pushpad, push-webhook, pusher-beams, appio Response
OK
Was this page helpful?
⌘I
Go
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.Credentials.Append(ctx, "<id>", components.UpdateSubscriberChannelRequestDto{
ProviderID: components.ChatOrPushProviderEnumOneSignal,
Credentials: components.ChannelCredentials{
WebhookURL: v3.Pointer("https://example.com/webhook"),
Channel: v3.Pointer("general"),
DeviceTokens: []string{
"token1",
"token2",
"token3",
},
AlertUID: v3.Pointer("12345-abcde"),
Title: v3.Pointer("Critical Alert"),
ImageURL: v3.Pointer("https://example.com/image.png"),
State: v3.Pointer("resolved"),
ExternalURL: v3.Pointer("https://example.com/details"),
},
}, nil)
if err != nil {
log.Fatal(err)
}
if res.SubscriberResponseDto != nil {
// handle response
}
}import { Novu } from "@novu/api";
const novu = new Novu({
secretKey: "YOUR_SECRET_KEY_HERE",
});
async function run() {
const result = await novu.subscribers.credentials.append({
providerId: "one-signal",
credentials: {
webhookUrl: "https://example.com/webhook",
channel: "general",
deviceTokens: [
"token1",
"token2",
"token3",
],
alertUid: "12345-abcde",
title: "Critical Alert",
imageUrl: "https://example.com/image.png",
state: "resolved",
externalUrl: "https://example.com/details",
},
}, "<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.AppendCredentialsAsync(
subscriberId: "<id>",
updateSubscriberChannelRequestDto: new UpdateSubscriberChannelRequestDto() {
ProviderId = ChatOrPushProviderEnum.OneSignal,
Credentials = new ChannelCredentials() {
WebhookUrl = "https://example.com/webhook",
Channel = "general",
DeviceTokens = new List<string>() {
"token1",
"token2",
"token3",
},
AlertUid = "12345-abcde",
Title = "Critical Alert",
ImageUrl = "https://example.com/image.png",
State = "resolved",
ExternalUrl = "https://example.com/details",
},
}
);
// 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();
$updateSubscriberChannelRequestDto = new Components\UpdateSubscriberChannelRequestDto(
providerId: Components\ChatOrPushProviderEnum::OneSignal,
credentials: new Components\ChannelCredentials(
webhookUrl: 'https://example.com/webhook',
channel: 'general',
deviceTokens: [
'token1',
'token2',
'token3',
],
alertUid: '12345-abcde',
title: 'Critical Alert',
imageUrl: 'https://example.com/image.png',
state: 'resolved',
externalUrl: 'https://example.com/details',
),
);
$response = $sdk->subscribersCredentials->append(
subscriberId: '<id>',
updateSubscriberChannelRequestDto: $updateSubscriberChannelRequestDto
);
if ($response->subscriberResponseDto !== null) {
// handle response
}import novu_py
from novu_py import Novu
with Novu(
secret_key="YOUR_SECRET_KEY_HERE",
) as novu:
res = novu.subscribers.credentials.append(subscriber_id="<id>", update_subscriber_channel_request_dto={
"provider_id": novu_py.ChatOrPushProviderEnum.ONE_SIGNAL,
"credentials": {
"webhook_url": "https://example.com/webhook",
"channel": "general",
"device_tokens": [
"token1",
"token2",
"token3",
],
"alert_uid": "12345-abcde",
"title": "Critical Alert",
"image_url": "https://example.com/image.png",
"state": "resolved",
"external_url": "https://example.com/details",
},
})
# Handle response
print(res)curl --request PATCH \
--url https://api.novu.co/v1/subscribers/{subscriberId}/credentials \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"credentials": {
"webhookUrl": "https://example.com/webhook",
"channel": "general",
"deviceTokens": [
"token1",
"token2",
"token3"
],
"alertUid": "12345-abcde",
"title": "Critical Alert",
"imageUrl": "https://example.com/image.png",
"state": "resolved",
"externalUrl": "https://example.com/details"
},
"integrationIdentifier": "<string>"
}
'const options = {
method: 'PATCH',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
credentials: {
webhookUrl: 'https://example.com/webhook',
channel: 'general',
deviceTokens: ['token1', 'token2', 'token3'],
alertUid: '12345-abcde',
title: 'Critical Alert',
imageUrl: 'https://example.com/image.png',
state: 'resolved',
externalUrl: 'https://example.com/details'
},
integrationIdentifier: '<string>'
})
};
fetch('https://api.novu.co/v1/subscribers/{subscriberId}/credentials', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));HttpResponse<String> response = Unirest.patch("https://api.novu.co/v1/subscribers/{subscriberId}/credentials")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"credentials\": {\n \"webhookUrl\": \"https://example.com/webhook\",\n \"channel\": \"general\",\n \"deviceTokens\": [\n \"token1\",\n \"token2\",\n \"token3\"\n ],\n \"alertUid\": \"12345-abcde\",\n \"title\": \"Critical Alert\",\n \"imageUrl\": \"https://example.com/image.png\",\n \"state\": \"resolved\",\n \"externalUrl\": \"https://example.com/details\"\n },\n \"integrationIdentifier\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.novu.co/v1/subscribers/{subscriberId}/credentials")
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 \"credentials\": {\n \"webhookUrl\": \"https://example.com/webhook\",\n \"channel\": \"general\",\n \"deviceTokens\": [\n \"token1\",\n \"token2\",\n \"token3\"\n ],\n \"alertUid\": \"12345-abcde\",\n \"title\": \"Critical Alert\",\n \"imageUrl\": \"https://example.com/image.png\",\n \"state\": \"resolved\",\n \"externalUrl\": \"https://example.com/details\"\n },\n \"integrationIdentifier\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"subscriberId": "<string>",
"_organizationId": "<string>",
"_environmentId": "<string>",
"deleted": true,
"createdAt": "<string>",
"updatedAt": "<string>",
"_id": "<string>",
"firstName": "<string>",
"lastName": "<string>",
"email": "<string>",
"phone": "<string>",
"avatar": "<string>",
"locale": "<string>",
"channels": [
{
"providerId": "slack",
"credentials": {
"webhookUrl": "https://example.com/webhook",
"channel": "general",
"deviceTokens": [
"token1",
"token2",
"token3"
],
"alertUid": "12345-abcde",
"title": "Critical Alert",
"imageUrl": "https://example.com/image.png",
"state": "resolved",
"externalUrl": "https://example.com/details"
},
"_integrationId": "<string>",
"integrationIdentifier": "<string>"
}
],
"topics": [
"<string>"
],
"isOnline": true,
"lastOnlineAt": "<string>",
"__v": 123,
"data": {},
"timezone": "<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."