Platform
Docs
Solutions
ContactLog In

Start Routing Notifications Today!

Courier is a notification service that centralizes all of your templates and messaging channels in one place which increases visibility and reduces engineering time.

Sign-up

Courier Live Header
LIVE STREAMINGCOURIER

Supporting Idempotent Requests with the Courier Node.js SDK

Aydrian Howard

August 12, 2020

During our August 5th Courier Live, I was joined by Riley Napier, one of our Sr. Software Engineers. Together we updated the Courier Node.js SDK to support our new Idempotent Requests feature.

Check out the video below to watch us:

  • Walk through the library code
  • Update the send function to support passing an idempotencyKey
  • Discuss how to handle changing TypeScript
  • Test our changes

Be sure to Like the video and Subscribe to our YouTube channel.

What is Idempotency?

Idempotency allows for safely retrying requests without accidentally performing the same operation twice. Imagine you were sending a notification using Courier and due to a network connection error, no response was received. At this point, you can't be sure if the notification was sent or not. No response means no messageId returned. An idempotent send would allow you to send the request again and if the message wasn't sent, it would send it. If it were sent, you would receive the messageId from the previous send. Courier supports idempotent requests for all POST requests by providing a unique key in the Idempotency-Key header. Any requests sent with the same idempotency key will be idempotent for as long as that key exists in our system. Learn more about how we handle Idempotent Requests in our API Reference documentation.

Idempotent Requests using the Node.js SDK

Once the changes Riley and I made are released, you'll be able to provide an idempotencyKey value in an optional config object for each function that sends a POST request.

1
import { CourierClient } from "@trycourier/courier";
2
import uuid4 from "uuid4";
3
4
const courier = CourierClient();
5
const idempotencyKey = uuid4();
6
7
async function run() {
8
const { messageId } = await courier.send(
9
{
10
eventId: "DOOF_ALERT",
11
recipientId: "AGENT-P-007",
12
profile: {
13
email: "perry@owca.org",
14
phone_number: "555-867-5309"
15
},
16
data: {
17
location: "Tri-State Area"
18
inator: "Shrinkinator"
19
}
20
},
21
{
22
idempotencyKey
23
}
24
);
25
console.log(messageId);
26
}
27
28
run();

Is there something you’d like to see us do using Courier? Let us know and it might be the subject of our next Courier Live. We stream a new Courier Live every Wednesday at noon Pacific.

Follow us on Twitch to be notified when we go live!

-Aydrian

Start Routing Notifications Today!

Courier is a notification service that centralizes all of your templates and messaging channels in one place which increases visibility and reduces engineering time.

Sign-up

More from Live Streaming

Decode Launch Thumbnail
LIVE STREAMINGCOURIER

Decode: Live Workshops to Build Exceptional Notification Experiences

Live coding workshops to build exceptional notification experiences for developers.

Shreya Gupta

Shreya Gupta

February 02, 2023

Courier Live Thumbnail
LIVE STREAMINGINTEGRATIONSCOURIER

No Code Notifications powered by Segment

Danny Douglass from our engineering team joined me for our August 12th Courier Live. We discussed a No Code approach to sending notifications using Courier as a Segment destination. It took less than 30 minutes from setup to sending our first notification.

Aydrian Howard

Aydrian Howard

August 19, 2020

Build your first notification in minutes

Send up to 10,000 notifications every month, for free.

Get started for free

Email & push notification

Build your first notification in minutes

Send up to 10,000 notifications every month, for free.

Get started for free

Email & push notification

Platform

Users

Content

Channels

Sending

Workflows

Preferences

Inbox

Workspaces

Observability

API Status

Changelog

© 2024 Courier. All rights reserved.