4

I am looking for a starting point on how to grab all public lists within the marketing cloud instance to show dynamically on my custom profile center that I am building. I am also looking to allow the subscriber to obviously be able to opt-in to these said public lists and return that information back to marketing cloud. I am currently using the boilerplate that has been resourced from here.

This also relates to grabbing all of the subscriber's non-hidden attributes that they have also.

Does grabbing these public lists and attributes include using SOAP API, or is there another way around using that like AMPscript?

1 Answer 1

6

Here's the SSJS function that I use to retrieve all of the Publication Lists. While it's not AMPscript, it can be translated:

function getAllPublicationLists() {

    var rr = Platform.Function.CreateObject("RetrieveRequest");
    Platform.Function.SetObjectProperty(rr, "ObjectType", "Publication");
    Platform.Function.SetObjectProperty(rr, "QueryAllAccounts", "True");

    Platform.Function.AddObjectArrayItem(rr, "Properties", "ID");
    Platform.Function.AddObjectArrayItem(rr, "Properties", "Name");
    Platform.Function.AddObjectArrayItem(rr, "Properties", "Category");
    Platform.Function.AddObjectArrayItem(rr, "Properties", "Client.ID");

    var reqParams = [0,0];
    var publications = Platform.Function.InvokeRetrieve(rr, reqParams);

    return publications;
}

If you just want the Public ones, here's a function for that:

function getAllPublicPublicationLists(mid) {

      var rr = Platform.Function.CreateObject("RetrieveRequest");
      Platform.Function.SetObjectProperty(rr, "ObjectType", "List");

      Platform.Function.AddObjectArrayItem(rr, "Properties", "ID");
      Platform.Function.AddObjectArrayItem(rr, "Properties", "ListName");
      Platform.Function.AddObjectArrayItem(rr, "Properties", "Description");

      var filter1 = Platform.Function.CreateObject("SimpleFilterPart");
      Platform.Function.SetObjectProperty(filter1, "Property", "Type");
      Platform.Function.SetObjectProperty(filter1, "SimpleOperator", "equals");
      Platform.Function.AddObjectArrayItem(filter1, "Value", "Public");

      var filter2 = Platform.Function.CreateObject("SimpleFilterPart");
      Platform.Function.SetObjectProperty(filter2, "Property", "ListClassification");
      Platform.Function.SetObjectProperty(filter2, "SimpleOperator", "equals");
      Platform.Function.AddObjectArrayItem(filter2, "Value", "PublicationList");

      var cfp = Platform.Function.CreateObject("ComplexFilterPart");
      Platform.Function.SetObjectProperty(cfp, "LeftOperand", filter1);
      Platform.Function.SetObjectProperty(cfp, "LogicalOperator", "AND");
      Platform.Function.SetObjectProperty(cfp, "RightOperand", filter2);

      Platform.Function.SetObjectProperty(rr, "Filter", cfp);

      var clid = Platform.Function.CreateObject("ClientID");
      Platform.Function.SetObjectProperty(clid, "ID", mid);
      Platform.Function.AddObjectArrayItem(rr, "ClientIDs", clid);

      var reqParams = [0, 0];
      var Lists = Platform.Function.InvokeRetrieve(rr, reqParams);

      return Lists;
}

To output them, you can iterate through the results like this:

var allPublicationLists = getAllPublicationLists();
for (var i in allPublicationLists) {
  Write("\n" + allPublicationLists[i]["ID"] + "|" +allPublicationLists[i]["Client"]["ID"] + "|" +allPublicationLists[i]["Name"]);
}

Then if you wanted to retrieve all of a subscriber's publications, then you can do something like this with the API Objects:

function getSubscriberLists(subscriberkey) {

    var rr = Platform.Function.CreateObject("RetrieveRequest");
    Platform.Function.SetObjectProperty(rr, "ObjectType", "ListSubscriber");

    Platform.Function.AddObjectArrayItem(rr, "Properties", "ListID");
    Platform.Function.AddObjectArrayItem(rr, "Properties", "SubscriberKey");
    Platform.Function.AddObjectArrayItem(rr, "Properties", "Status");

    var filter = Platform.Function.CreateObject("SimpleFilterPart");
    Platform.Function.SetObjectProperty(filter, "Property", "SubscriberKey");
    Platform.Function.SetObjectProperty(filter, "SimpleOperator", "equals");
    Platform.Function.AddObjectArrayItem(filter, "Value", subscriberkey);
    Platform.Function.SetObjectProperty(rr, "Filter", filter);

    var reqParams = [0,0];
    var subscriberLists = Platform.Function.InvokeRetrieve(rr, reqParams);

    return subscriberLists;
}

If you wanted to just get non-Publication lists:

function getAllLists(mid) {

      var rr = Platform.Function.CreateObject("RetrieveRequest");
      Platform.Function.SetObjectProperty(rr, "ObjectType", "List");

      Platform.Function.AddObjectArrayItem(rr, "Properties", "ID");
      Platform.Function.AddObjectArrayItem(rr, "Properties", "ListName");
      Platform.Function.AddObjectArrayItem(rr, "Properties", "Description");

      var filter1 = Platform.Function.CreateObject("SimpleFilterPart");
      Platform.Function.SetObjectProperty(filter1, "Property", "Type");
      Platform.Function.SetObjectProperty(filter1, "SimpleOperator", "equals");
      Platform.Function.AddObjectArrayItem(filter1, "Value", "Public");

      var filter2 = Platform.Function.CreateObject("SimpleFilterPart");
      Platform.Function.SetObjectProperty(filter2, "Property", "ListClassification");
      Platform.Function.SetObjectProperty(filter2, "SimpleOperator", "notEquals");
      Platform.Function.AddObjectArrayItem(filter2, "Value", "PublicationList");

      var cfp = Platform.Function.CreateObject("ComplexFilterPart");
      Platform.Function.SetObjectProperty(cfp, "LeftOperand", filter1);
      Platform.Function.SetObjectProperty(cfp, "LogicalOperator", "AND");
      Platform.Function.SetObjectProperty(cfp, "RightOperand", filter2);

      Platform.Function.SetObjectProperty(rr, "Filter", cfp);

      var clid = Platform.Function.CreateObject("ClientID");
      Platform.Function.SetObjectProperty(clid, "ID", mid);
      Platform.Function.AddObjectArrayItem(rr, "ClientIDs", clid);

      var reqParams = [0, 0];
      var Lists = Platform.Function.InvokeRetrieve(rr, reqParams);

      return Lists;
}
7
  • Thanks for the response! After grabbing all of the lists, how does it translate to showing on a landing page? Like if I wanted to show all of the lists that I grabbed.
    – Evan
    Jun 1, 2018 at 13:38
  • I've updated my post to include a loop... Some of this will be different with AMPscript. Jun 1, 2018 at 13:45
  • Also added a function that retrieves only Public Publication lists Jun 1, 2018 at 13:53
  • Awesome! I'll check to see if printing those out work. Is there a way to just grab "Lists" or is it just only publication lists?
    – Evan
    Jun 1, 2018 at 13:54
  • You can change the ComplexFilterPart in getAllPublicPublicationLists() to retrieve Lists only. Jun 1, 2018 at 14:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .