DEV Community

Cover image for Streamline your workflow with CourierJS: Our new client-side SDK
Charla Bigelow for Courier

Posted on • Originally published at courier.com

Streamline your workflow with CourierJS: Our new client-side SDK

We are thrilled to announce the release of our first client-side SDK for Courier, written for JavaScript. This new addition expands our existing SDK offerings, which include Java, Python, Node, Go, Ruby, and PHP, and makes it even easier for developers to integrate Courier into their projects. By enabling direct calls to Courier within your JavaScript code, you can eliminate the need to use a back-end service as an extra layer between your front end and the Courier API, saving valuable time and resources.

With the initial release, we're introducing three new API calls: the identify call for tying a user to actions they perform, such as logging in or updating their profile, and the subscribe and unsubscribe calls for subscribing and unsubscribing to lists. By simplifying these key interactions, CourierJS enhances the overall experience of using Courier.

Client-side vs. Server-side SDKs

You may still be wondering: why introduce a client-side JavaScript SDK for Courier when we already have SDKs for many other languages? Let's dive into the differences between client-side and server-side SDKs, which will help you determine the right type of SDK for your specific needs.

Client-side SDK benefits
(Comparing integration flows: with and without Courier client-side SDK)

Client-side SDKs are designed to provide a way for you to interact with an API within your application's front-end code. Server-side SDKs, in contrast, interact with your back-end code, making them more suitable for processing and handling data that doesn't directly involve user interactions on the front end. By offering a client-side JavaScript SDK, we're providing developers with an alternative to server-side SDKs that is more suitable when you need to integrate Courier's functionality directly into your web application's front end. When trying to call the API from your front end, having an extra layer of back-end code might not always be the most suitable option for certain use cases. With CourierJS, we provide an alternative that streamlines the process and caters to a broader range of scenarios, enhancing efficiency and helping you deliver valuable applications more quickly.

We have taken inspiration from popular customer data platforms like Segment and RudderStack, both of which provide an identify call. In addition to an identify call, which ties a user action to a particular user, our initial release also includes support for subscribing and unsubscribing to lists, allowing users to manage their communication preferences with ease.

The JavaScript SDK has been designed to be both intuitive and efficient, working exactly how you'd expect. Instead of issuing multiple commands to update specific fields, you can now easily update multiple fields in a single operation. For example, if you have a user with an ID, name, email address, physical address, and phone number, and you just want to update the email address and phone number, you can pass in just those values. The SDK also automatically merges new data with pre-existing data, overwriting only the specified fields. This functionality ensures a smooth integration with your front-end code and a more seamless user experience.

Discover the advantages of CourierJS

Previously, developers using Courier only had access to server-side SDKs. These SDKs required the front-end code to communicate with the back-end services to utilize Courier's functionality, often adding an unnecessary extra layer. In some cases, you even had to create an entire back-end service just to handle the Courier SDK.

One of the primary challenges faced when using server-side SDKs in the context of Courier arises when you need to send data from the front end to Courier, which previously required going through the back end. This process can be manageable, but it can also be tedious for developers who want a more streamlined solution. To address this, we’ve developed the client-side SDK, making it easier for those who want to directly integrate Courier's functionality into their web application's front end, bypassing the need to pass data through the back end first.

By introducing the new Courier client-side SDK, we aim to simplify this process and reduce the workload for engineers. This not only saves time but also accelerates the implementation of new features, making your development process more efficient and agile.

Ready to get started? Using CourierJS is a breeze

Now that you've discovered the advantages of the Courier client-side SDK, it's time to dive into how you can seamlessly integrate it into your project. To begin, all you need to do is install the JavaScript package and start using the provided function calls in your code. For a comprehensive step-by-step guide on setting up the Courier client-side SDK, you can refer to our documentation here.

Exploring the new API calls in Courier's client-side SDK

Now that you're all set up, let's take a closer look at the new API calls introduced in the SDK.

The identify call

The identify call allows you to create and update user profiles with ease. Here's an example of how the identify call can be used in your code:

await courierSDK.identify("user123", {
  email: "user123@example.com",
  firstName: "John",
  lastName: "Doe",
});
Enter fullscreen mode Exit fullscreen mode

In this example, the identify call creates or updates a user profile with the specified user ID, email, first name, and last name. The simplicity of the call ensures that you can quickly and easily update user profiles as needed, making it an invaluable tool in your communication management toolkit.

Subscribing and unsubscribing from lists

A list in Courier is a way to group recipient profiles, allowing you to send a message to all subscribed recipients with a single call. This feature is particularly useful for managing newsletters, product updates, and other types of mass communication.

Managing user subscriptions is easy with the new subscribe and unsubscribe API calls. These calls make it straightforward to maintain up-to-date lists of subscribers, due to not needing to call a back-end service. Here are examples of how to use the subscribe and unsubscribe calls in your code:

// Subscribe a user to a list
await courierSDK.subscribe("user123", "my-newsletter-list");

// Unsubscribe a user from a list
await courierSDK.unsubscribe("user123", "my-newsletter-list");
Enter fullscreen mode Exit fullscreen mode

As you can see from the comments in these examples, the subscribe call adds a user to a specified list, while the unsubscribe call removes them from the list.

By incorporating these new API calls into your project, you can further streamline your development process.

Conclusion

Throughout this article, we've unveiled the power of the new CourierJS client-side SDK and explored its features, including the identify call and subscribe and unsubscribe calls. By using the CourierJS client-side SDK, you can reduce the workload involved in your development process and improve the overall efficiency of your projects.

As you’ve seen, the SDK saves you time and effort by eliminating the need for complex back-end services and enabling direct communication between the front end and Courier. Its intuitive functionality, ease of use, and powerful capabilities make it a valuable addition to your development toolkit.

We encourage you to try out the new CourierJS client-side SDK and experience the benefits it offers firsthand. By adopting this innovative tool, you can enhance your product-triggered communication management and unlock the full potential of the Courier ecosystem.

Top comments (0)