Log InSign Up
All Posts
Courier Live Header

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


More from Courier Live

April 2021 Courier Live Release Notes Thumbnail

Courier April Product Release Updates: In-app Inbox, Preferences, and Automations

In this update, Aydrian and Nate (Head of Customer Success) as cohosts cover what is new with the in-app notifications API, our new preferences component, and our automations API, which is now GA.

Aydrian Howard

Aydrian Howard

May 20, 2021

Courier Live Thumbnail

Courier Live: Content, Notifications, and IoT

On February 2nd and 3rd, Shy Ruparel joined Aydrian for another Courier and Contentful crossover stream. This time, they decided to play around with an IoT E-ink display and use it to show the latest posts from Contentful and send notifications using Courier.

Aydrian Howard

Aydrian Howard

February 10, 2021

Build your first notification in minutes

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

Email & push notification

Build your first notification in minutes

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

Email & push notification









© 2022 Courier. All rights reserved.