Lists

Methods to create and manage lists using Node SDK

The Lists SDK methods lets you create a list of subscribers. You can then send bulk messages to all the subscribers in the list with a single API call.

Data structure of List:

{
	"list_id": "list_1",
	"list_name": "city_san_francisco",
	"list_description: "All Users whose last updated city is San Francisco"
}

Field Description:

list_id (*mandatory)

Unique identifier for the list. Follow these guidelines for naming the list:

  • list_id can be of max 64 characters.
  • It can contain characters [a-z0-9_-] i.e. alphanumeric characters, _(underscore) and -(hyphen).
  • list_id is case-insensitive. Suprsend first converts list_id to lowercase before storing it or doing any sort of comparison on it.

list_name (optional)

Name of the list. This is for your reference and can be referred to understand what this list is for.

description (optional)

Description of the list to identify what type of users belong to this list.


Below are some methods that you can use to create and update list

1. Creating List

a. Create a new list

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

const supr_client = new Suprsend(
  "_api_key_",
  "_api_secret_"
);

//create list
const data = 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));

b. Get list data

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

const supr_client = new Suprsend(
  "_api_key_",
  "_api_secret_"
);

//get list details
const data = supr_client.subscriber_lists.get("_list_id_");

data.then((res) => console.log(res)).catch((err) => console.log(err));

Response

{
	"list_id": "list-id",
	"list_name": "List Name",
  "updated_at": "2022-12-18T10:40:27.268417+00:00",
	"list_description": "List description"
}

c. Get all lists

To get the data of all the lists created in your workspace

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

const supr_client = new Suprsend(
  "_api_key_",
  "_api_secret_"
);

//get all lists' details
const data = supr_client.subscriber_lists.get_all();

data.then((res) => console.log(res)).catch((err) => console.log(err));

Response

{
  "meta": {
    "limit": 20,
    "offset": 0,
    "count": 1
  },
  "results": [
    {
      "list_id": "list-id1",
      "list_name": "List Name1",
      "updated_at": "2022-12-18T10:40:27.268417+00:00",
      "list_description": "List description1"
    },
    {
      "list_id": "list-id2",
      "list_name": "List Name2",
      "updated_at": "2022-12-19T10:40:27.268417+00:00",
      "list_description": "List description2"
    }
  ]
}


2. Adding Subscribers to the list

a. Add subscribers

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

const supr_client = new Suprsend(
  "_api_key_",
  "_api_secret_"
);

//add subscribers by passing an array of distinct_ids
const data = supr_client.subscriber_lists.add("_list_id_", [
  "_distinct_id1_",
  "_distinct_id2_"
]);

data.then((res) => console.log(res)).catch((err) => console.log(err));


b. Remove subscribers

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

const supr_client = new Suprsend(
  "_api_key_",
  "_api_secret_"
);

//remove subscribers by passing an array of distinct_ids
const data = supr_client.subscriber_lists.remove("_list_id_", [
  "_distinct_id1_",
  "_distinct_id2_"
]);

data.then((res) => console.log(res)).catch((err) => console.log(err));