Message Routing REST API (v2.4.2)

Download OpenAPI specification:Download

Using the Message routing API

Managing webhook Destinations

Receiving messages

Triggering message forwarding

  • Send a device message from a device to initiate message forwarding.
  • Await messages at your registered webhook Destination shortly after sending the device message.
  • Messages arrive in batches to your configured webhook Destination.
  • Messages from MQTT topics prefixed with $ENV/$TEAM_ID/m are forwarded, with the exception of messages sent to $ENV/$TEAM_ID/m/d/$DEVICE_ID/d2c/bin.

Security and SSL verification

  • Verifying requests: Use the x-nrfcloud-signature header to verify incoming requests. This signature is an HMAC hex digest of the request payload, hashed using your provided secret. Employ constant-time string comparisons to mitigate timing attacks.
  • SSL verification: SSL verification is standard for payload delivery unless you disable it using the verifySsl property in your webhook configuration.

Handling errors

  • Non-2xx responses from your Destination webhook are logged as errors. Access the errors property of the Destination to review the five most recent errors within the past 30 days.

Access control

  • Full Destination management is limited to Admin and Owner roles. Destination viewing is allowed for Editor and Viewer roles.

Webhook server example

Below is an example of a simple Node.js server that receives webhook requests, verifies the x-nrfcloud-signature header, and responds with a status code of 200 along with the x-nrfcloud-team-id header. This example uses Express, a popular web framework for Node.js, and the crypto module for signature verification.

const express = require('express');
const bodyParser = require('body-parser');
const crypto = require('crypto');

const app = express();
const port = 3000;

// Replace this with your actual secret key
const secretKey = 'yourSecretKey';

app.use(bodyParser.json());

// Verify nRF Cloud signature
const verifySignature = (req) => {
    const signature = req.headers['x-nrfcloud-signature'];
    const body = JSON.stringify(req.body);

    // Create HMAC hex digest
    const hmac = crypto.createHmac('sha256', secretKey);
    hmac.update(body, 'utf8');
    const digest = hmac.digest('hex');

    return digest === signature;
};

app.post('/webhook', (req, res) => {
    if (verifySignature(req)) {
        // Your logic here - process the request
        
        // Respond with 200 OK and x-nrfcloud-team-id header
        res.set('x-nrfcloud-team-id', 'yourTeamId');
        res.status(200).send('Webhook received successfully.');
    } else {
        res.status(401).send('Invalid signature.');
    }
});

app.listen(port, () => {
    console.log(`Webhook receiver running on port ${port}`);
});

Destination

ListDestinations

Returns a list of all Destinations registered to your team.

query Parameters
pageLimit
number (PageLimit)
Examples:
  • pageLimit=100 -
pageNextToken
string (PageToken) [ 1 .. 256 ] characters ^[^\s]{1,256}$
Examples:
  • pageNextToken=def456eubdkw9038kdd93l -

Token used to retrieve the next page of items in the list. Present in a response only if the total available results exceeds the specified limit on a page. This token does not change between requests. When supplying as a request parameter, use URL-encoding.

Responses

Response samples

Content type
application/json
{
  • "items": [
    ],
  • "total": 1,
  • "pageNextToken": "def456"
}

CreateDestination

Registers a new Destination to forward device messages from nRF Cloud.

During the request, the service verifies your provided Destination. Before creating a new Destination, ensure your server responds appropriately. nRF Cloud needs to verify that you own this endpoint and that it is ready to start receiving data. The service sends a POST request to the URL endpoint you provided. Your endpoint should respond with a 2xx status code and the header x-nrfcloud-team-id with your team ID. If the verification process fails, the request responds with a 400 status code and the Destination is not registered.

Request Body schema: application/json
required
name
required
string non-empty
required
object (WritableHttpConfiguration)
isEnabled
required
boolean

If true, the Destination is enabled and will forward messages. If false, the Destination is disabled and will not forward messages.

dlqNotificationEmails
required
Array of strings (Email) [^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2...]

The email address to which DLQ notifications are sent.

Responses

Request samples

Content type
application/json
{}

Response samples

Content type
application/json
{
  • "id": "f7de2039-06bd-4da5-b493-7ed0a038ccf3",
  • "name": "Test Destination 01",
  • "config": {},
  • "isEnabled": true,
  • "errors": [ ],
  • "dlqSize": 0,
  • "dlqNotificationEmails": [
    ],
  • "createdAt": "2024-09-19 00:00:17.867+00",
  • "verified": false
}

TestDestination

Sends a message to your Destination for testing purposes.

path Parameters
required
NominalStringUuid (string) <uuid> = 36 characters ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3...
Examples:
  • f7de2039-06bd-4da5-b493-7ed0a038ccf3 -

Universally unique identifier

Request Body schema: application/json
Schema not provided

Responses

Request samples

Content type
application/json
null

Response samples

Content type
application/json
{
  • "destinationResponse": {
    }
}

UpdateDestination

Modifies an existing Destination to forward device messages from nRF Cloud. If you alter the Destination URL, re-verification is required. See Create a new Destination for more information about verification.

path Parameters
required
NominalStringUuid (string) <uuid> (Uuid) = 36 characters ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3...
Examples:
  • f7de2039-06bd-4da5-b493-7ed0a038ccf3 -

Universally unique identifier

Request Body schema: application/json
required
name
string non-empty
isEnabled
boolean

If true, the Destination is enabled and will forward messages. If false, the Destination is disabled and will not forward messages.

dlqNotificationEmails
Array of strings (Email) [^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2...]

The email address to which DLQ notifications are sent.

object

Responses

Request samples

Content type
application/json
{
  • "name": "Test Destination 02",
  • "config": {},
  • "dlqNotificationEmails": [
    ],
  • "isEnabled": true
}

DeleteDestination

Removes a Destination from your team.

path Parameters
required
NominalStringUuid (string) <uuid> = 36 characters ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3...
Examples:
  • f7de2039-06bd-4da5-b493-7ed0a038ccf3 -

Universally unique identifier

Responses

Send Verification

Sends a Verification token to the Destination. For HTTP Destinations, Message Routing Service sends the verification token via POST request to your configured url. Here is an example of the payload that will be sent to the destination:

{
  "type": "system.verification",
  "messages": [{ "verificationToken": "012345"}],
  "timestamp": "2024-10-03T22:37:56.936Z"
}

This token can then be used to verify the destination using the verification endpoint

Authorizations:
ApiKey
path Parameters
required
NominalStringUuid (string) <uuid> = 36 characters ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3...
Examples: a5592ec1-18ae-4d9d-bc44-1d9bd927bbe9

Universally unique identifier

Responses

Verify Destination

Verify the Destination. Successful verifications will mark the destination as verified and will allow Message Routing Service to start sending messages to the destination. For HTTP Destinations, Message Routing Service sends the verification token via POST request to your configured url. This occur when you create the destination or update the url of the destination. You can also resend a verification tokens using the send verification endpoint.

Authorizations:
ApiKey
path Parameters
required
NominalStringUuid (string) <uuid> = 36 characters ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3...
Examples: a5592ec1-18ae-4d9d-bc44-1d9bd927bbe9

Universally unique identifier

Request Body schema: application/json
required
verificationToken
required
string^\d{6}$

The verification token used to verify the destination. This should match the numeric token sent to the destination url via POST.

Responses

Request samples

Content type
application/json
{
  • "verificationToken": "012345"
}

DLQ

ListDLQItems

List the items in the Dead-Letter Queue (DLQ) for a Destination.

path Parameters
required
NominalStringUuid (string) <uuid> = 36 characters ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3...
Examples:
  • f7de2039-06bd-4da5-b493-7ed0a038ccf3 -

Universally unique identifier

query Parameters
pageLimit
number (PageLimit)
Examples:
  • pageLimit=100 -
pageNextToken
string (PageToken) [ 1 .. 256 ] characters ^[^\s]{1,256}$
Examples:
  • pageNextToken=def456eubdkw9038kdd93l -

Token used to retrieve the next page of items in the list. Present in a response only if the total available results exceeds the specified limit on a page. This token does not change between requests. When supplying as a request parameter, use URL-encoding.

Responses

Response samples

Content type
application/json
{
  • "items": [
    ],
  • "total": 1,
  • "pageNextToken": "def456"
}

DeleteDLQItems

Delete every item in the DLQ for a Destination. This is permanent.

path Parameters
required
NominalStringUuid (string) <uuid> = 36 characters ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3...
Examples:
  • f7de2039-06bd-4da5-b493-7ed0a038ccf3 -

Universally unique identifier

Responses