Pulling Subscriber Status from Lists using SSJS

I am looking to pull the status of a subscriber whenever they click on the profile center URL link within emails. I have created a custom profile center that pulls all of the lists that I have created onto the page, but I am looking to have another column to tell the user that they are already active or unsubscribed to a list. I have tried using AMPscript but it did not seem to work, so I am looking for a way to pull these statuses using SSJS and then printing it out on the HTML page for the user to see.

If you need any more details, let me know!


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Use the following code to determine which Lists (also Publication Lists) a subscriber is a part of.

Make sure your email is using %%=MicrositeURL(xxxxx)=%% or %%=RedirectTo(CloudPagesURL(xxxxx))=%%.

This ensures that the Landing Page/CloudPage has access to the subscriber’s attributes (such as Subscriber Key)

    SET @subscriberKey = _subscriberkey /*Retrieve the Subscriber Key into a variable*/

<script runat="server">
    Platform.Load("core", "1.1.1")
    var subKey = Variable.GetValue("@subscriberKey") //Assign to SSJS variable
    var subObj = Subscriber.Init(subkey) //Initiate Subscriber Object
    var listJSON = subObj.Lists.Retrieve() //Retrieve lists that the subscribers is a part of
    for (var i = 0; i < listJSON.length; i++){ //Loop through all the lists and print them out in HTML
        var listName = listJSON[i]["List"]["Name"]
        var listStatus = listJSON[i]["Status"]
     List Name:<ctrl:var name=listName /> <br />
     List Status:<ctrl:var name=listStatus /> <br />
<script runat="server">
    Platform.Load("core", "1.1.1")    
    } //End of loop
    Write("Debug - Subscriber JSON:" + Stringify(listJSON)) //Used for debugging to find the object names

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x