Environments
Publish resources to target environment
Publishes all workflows and resources from the source environment to the target environment. Optionally specify specific resources to publish or use dryRun mode to preview changes.
POST
/
v2
/
environments
/
{targetEnvironmentId}
/
publish
TypeScript
import { Novu } from "@novu/api";
const novu = new Novu({
secretKey: "YOUR_SECRET_KEY_HERE",
});
async function run() {
const result = await novu.environments.publish({
sourceEnvironmentId: "507f1f77bcf86cd799439011",
resources: [
{
resourceType: "REGULAR",
resourceId: "workflow-id-1",
},
],
}, "6615943e7ace93b0540ae377");
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.Environments.PublishAsync(
targetEnvironmentId: "6615943e7ace93b0540ae377",
publishEnvironmentRequestDto: new PublishEnvironmentRequestDto() {
SourceEnvironmentId = "507f1f77bcf86cd799439011",
Resources = new List<ResourceToPublishDto>() {
new ResourceToPublishDto() {
ResourceType = ResourceTypeEnum.Regular,
ResourceId = "workflow-id-1",
},
},
}
);
// 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();
$publishEnvironmentRequestDto = new Components\PublishEnvironmentRequestDto(
sourceEnvironmentId: '507f1f77bcf86cd799439011',
resources: [
new Components\ResourceToPublishDto(
resourceType: Components\ResourceTypeEnum::Regular,
resourceId: 'workflow-id-1',
),
],
);
$response = $sdk->environments->publish(
targetEnvironmentId: '6615943e7ace93b0540ae377',
publishEnvironmentRequestDto: $publishEnvironmentRequestDto
);
if ($response->publishEnvironmentResponseDto !== null) {
// handle response
}import novu_py
from novu_py import Novu
with Novu(
secret_key="YOUR_SECRET_KEY_HERE",
) as novu:
res = novu.environments.publish(target_environment_id="6615943e7ace93b0540ae377", publish_environment_request_dto={
"source_environment_id": "507f1f77bcf86cd799439011",
"resources": [
{
"resource_type": novu_py.ResourceTypeEnum.REGULAR,
"resource_id": "workflow-id-1",
},
],
})
# 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.Environments.Publish(ctx, "6615943e7ace93b0540ae377", components.PublishEnvironmentRequestDto{
SourceEnvironmentID: v3.Pointer("507f1f77bcf86cd799439011"),
Resources: []components.ResourceToPublishDto{
components.ResourceToPublishDto{
ResourceType: components.ResourceTypeEnumRegular,
ResourceID: "workflow-id-1",
},
},
}, nil)
if err != nil {
log.Fatal(err)
}
if res.PublishEnvironmentResponseDto != nil {
// handle response
}
}curl --request POST \
--url https://api.novu.co/v2/environments/{targetEnvironmentId}/publish \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"sourceEnvironmentId": "507f1f77bcf86cd799439011",
"dryRun": false,
"resources": [
{
"resourceId": "workflow-id-1"
}
]
}
'const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
sourceEnvironmentId: '507f1f77bcf86cd799439011',
dryRun: false,
resources: [{resourceId: 'workflow-id-1'}]
})
};
fetch('https://api.novu.co/v2/environments/{targetEnvironmentId}/publish', 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/environments/{targetEnvironmentId}/publish")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"sourceEnvironmentId\": \"507f1f77bcf86cd799439011\",\n \"dryRun\": false,\n \"resources\": [\n {\n \"resourceId\": \"workflow-id-1\"\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.novu.co/v2/environments/{targetEnvironmentId}/publish")
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 \"sourceEnvironmentId\": \"507f1f77bcf86cd799439011\",\n \"dryRun\": false,\n \"resources\": [\n {\n \"resourceId\": \"workflow-id-1\"\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"results": [
{
"successful": [
{
"resourceId": "<string>",
"resourceName": "<string>"
}
],
"failed": [
{
"resourceId": "<string>",
"resourceName": "<string>",
"error": "<string>",
"stack": "<string>"
}
],
"skipped": [
{
"resourceId": "<string>",
"resourceName": "<string>",
"reason": "<string>"
}
],
"totalProcessed": 123
}
],
"summary": {
"resources": 123,
"successful": 123,
"failed": 123,
"skipped": 123
}
}{
"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
Target environment ID (MongoDB ObjectId) to publish resources to
Body
application/json
Publish request configuration
Source environment ID to sync from. Defaults to the Development environment if not provided.
Example:
"507f1f77bcf86cd799439011"
Perform a dry run without making actual changes
Array of specific resources to publish. If not provided, all resources will be published.
Show child attributes
Show child attributes
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.environments.publish({
sourceEnvironmentId: "507f1f77bcf86cd799439011",
resources: [
{
resourceType: "REGULAR",
resourceId: "workflow-id-1",
},
],
}, "6615943e7ace93b0540ae377");
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.Environments.PublishAsync(
targetEnvironmentId: "6615943e7ace93b0540ae377",
publishEnvironmentRequestDto: new PublishEnvironmentRequestDto() {
SourceEnvironmentId = "507f1f77bcf86cd799439011",
Resources = new List<ResourceToPublishDto>() {
new ResourceToPublishDto() {
ResourceType = ResourceTypeEnum.Regular,
ResourceId = "workflow-id-1",
},
},
}
);
// 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();
$publishEnvironmentRequestDto = new Components\PublishEnvironmentRequestDto(
sourceEnvironmentId: '507f1f77bcf86cd799439011',
resources: [
new Components\ResourceToPublishDto(
resourceType: Components\ResourceTypeEnum::Regular,
resourceId: 'workflow-id-1',
),
],
);
$response = $sdk->environments->publish(
targetEnvironmentId: '6615943e7ace93b0540ae377',
publishEnvironmentRequestDto: $publishEnvironmentRequestDto
);
if ($response->publishEnvironmentResponseDto !== null) {
// handle response
}import novu_py
from novu_py import Novu
with Novu(
secret_key="YOUR_SECRET_KEY_HERE",
) as novu:
res = novu.environments.publish(target_environment_id="6615943e7ace93b0540ae377", publish_environment_request_dto={
"source_environment_id": "507f1f77bcf86cd799439011",
"resources": [
{
"resource_type": novu_py.ResourceTypeEnum.REGULAR,
"resource_id": "workflow-id-1",
},
],
})
# 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.Environments.Publish(ctx, "6615943e7ace93b0540ae377", components.PublishEnvironmentRequestDto{
SourceEnvironmentID: v3.Pointer("507f1f77bcf86cd799439011"),
Resources: []components.ResourceToPublishDto{
components.ResourceToPublishDto{
ResourceType: components.ResourceTypeEnumRegular,
ResourceID: "workflow-id-1",
},
},
}, nil)
if err != nil {
log.Fatal(err)
}
if res.PublishEnvironmentResponseDto != nil {
// handle response
}
}curl --request POST \
--url https://api.novu.co/v2/environments/{targetEnvironmentId}/publish \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"sourceEnvironmentId": "507f1f77bcf86cd799439011",
"dryRun": false,
"resources": [
{
"resourceId": "workflow-id-1"
}
]
}
'const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
sourceEnvironmentId: '507f1f77bcf86cd799439011',
dryRun: false,
resources: [{resourceId: 'workflow-id-1'}]
})
};
fetch('https://api.novu.co/v2/environments/{targetEnvironmentId}/publish', 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/environments/{targetEnvironmentId}/publish")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"sourceEnvironmentId\": \"507f1f77bcf86cd799439011\",\n \"dryRun\": false,\n \"resources\": [\n {\n \"resourceId\": \"workflow-id-1\"\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.novu.co/v2/environments/{targetEnvironmentId}/publish")
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 \"sourceEnvironmentId\": \"507f1f77bcf86cd799439011\",\n \"dryRun\": false,\n \"resources\": [\n {\n \"resourceId\": \"workflow-id-1\"\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"results": [
{
"successful": [
{
"resourceId": "<string>",
"resourceName": "<string>"
}
],
"failed": [
{
"resourceId": "<string>",
"resourceName": "<string>",
"error": "<string>",
"stack": "<string>"
}
],
"skipped": [
{
"resourceId": "<string>",
"resourceName": "<string>",
"reason": "<string>"
}
],
"totalProcessed": 123
}
],
"summary": {
"resources": 123,
"successful": 123,
"failed": 123,
"skipped": 123
}
}{
"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."