@trycourier/courier-js exposes the Courier APIs for web browser-based applications.If you’re looking for full-featured UI components,
check out Courier React or Courier UI Web Components.
To use the SDK, you need to generate a JWT (JSON Web Token) for your user. This JWT should always be generated by your backend server, never in client-side code.
When your app needs to authenticate a user, your client
should make a request to your own backend (ex. GET https://your-awesome-app.com/api/generate-courier-jwt).
Use the Courier Inbox APIs to read and update inbox messages.
Copy
Ask AI
import { CourierClient } from '@trycourier/courier-js';const courierClient = new CourierClient({ userId: 'my-user-id', jwt: 'eyJ.mock.jwt',});// Fetch inbox messages for the authenticated userconst inboxMessages = await courierClient.inbox.getMessages();// Fetch archived messages for the authenticated userconst archivedMessages = await courierClient.inbox.getArchivedMessages();// Get the message id and tracking ids for the first messageconst { messageId, trackingIds } = inboxMessages.data.messages.nodes[0];// Mark a message "clicked"await courierClient.inbox.click({ messageId, trackingId: trackingIds.clickTrackingId,});// Mark a message "read"await courierClient.inbox.read({ messageId });// Mark a message "unread"await courierClient.inbox.unread({ messageId });// Mark a message "opened"await courierClient.inbox.open({ messageId });// Archive a messageawait courierClient.inbox.archive({ messageId });// Unarchive a messageawait courierClient.inbox.unarchive({ messageId });// Mark all messages "read"await courierClient.inbox.readAll();// Archive all "read" messagesawait courierClient.inbox.archiveRead();// Archive all inbox messagesawait courierClient.inbox.archiveAll();
Use the Courier Lists APIs to subscribe and unsubscribe users to lists. See Lists for more information.
Copy
Ask AI
// Subscribes the authenticated user to listIdawait courierClient.lists.putSubscription({ listId: 'your_list_id'});// Unsubscribes the authenticated user from listIdawait courierClient.lists.deleteSubscription({ listId: 'your_list_id'});