Lists

Methods to create and manage lists using Node SDK

List methods lets you manage a list and subscribers in that list. You can then send bulk messages to all the subscribers in the list with a single API call.

Create list

const { Suprsend } = require("@suprsend/node-sdk");

const supr_client = new Suprsend("workspace_key", "workspace_secret");

// create list api call
const response = supr_client.subscriber_lists.create({
  list_id: "_list_id_",
  list_name: "_list_name_",
  list_description: "_some sample descritpion for list_",
});

data.then((res) => console.log(res)).catch((err) => console.log(err));
PropertyDescription
list_idmax 64 characters and should contains alphanumeric characters(a-z, 0-9), hyphen (-) and underscode(_).
list_name (Optional)Name of the list. This is for your reference and can be referred to understand what this list is for.
list_description (Optional)Description of the list to identify what type of users belong to this list.

Get list details

const data = supr_client.subscriber_lists.get("_list_id_");
{
	"list_id": "list-id",
	"list_name": "List Name",
  "updated_at": "2022-12-18T10:40:27.268417+00:00",
	"list_description": "List description"
}

Get list of lists

const data = supr_client.subscriber_lists.get_all(); // default limit 20

const data = supr_client.subscriber_lists.get_all({limit:20, offset:0}); //  max limit 1000

Add subscribers to list

const list_id = "_list_id_";
const subscribers = ["_distinct_id1_","_distinct_id2_", ..... ];

const data = supr_client.subscriber_lists.add(list_id, subscribers);

Remove subscribers from list

const list_id = "_list_id_";
const subscribers = ["_distinct_id1_","_distinct_id2_", ..... ];

const data = supr_client.subscriber_lists.remove(list_id, subscribers);

Delete list

const data = supr_client.subscriber_lists.delete("_list_id_");

Replace users from the list

In case you want to refresh list with a new set of users completely, you can replace users by creating a draft version of the list and updating users in it.

1. Start Sync to create draft version of the list

This method will create a draft version of the list where you can add the new set of users to replace users.

const data = supr_client.subscriber_lists.start_sync("_list_id_");


2. Add Subscribers to draft list

You can use this method to add subscribers to List draft version created in Step 1. You'll get version_id in start sync response.

const data = supr_client.subscriber_lists.add_to_version("_list_id_", "01HHCTXXXXXXXXXXX", ["_user_id_1","user_id_2"])



3. Remove Subscribers from draft list

You can use this method to remove subscribers from List draft version created in Step 1. You'll get version_id in start sync response.

const data = supr_client.subscriber_lists.remove_from_version("_list_id_", "01HHCTXXXXXXXXXXX", ["_user_id_1","_user_id_2"])


4. Finish Sync to make the draft version live

Once your subscribers are updated in the list, use this method to finish sync and make the draft version updated in above steps live.

const data = supr_client.subscriber_lists.finish_sync("_list_id_", "01HHCTXXXXXXXXXXX")


Delete Draft list

You can also delete draft list if it's created by mistake.

const data = supr_client.subscriber_lists.delete_version("_list_id_", "01HHCTXXXXXXXXXXX");


What’s Next

Send broadcast notification to users in list