verified
Retrieve a ListLearn how to retrieve a List in Salesforce Marketing Cloud (SFMC) with SSJS (server-side JavaScript). Code snippets include Core and WSProxy methods.
Core
var filter = {
Property: "ListName",
SimpleOperator: "equals",
Value: "MyNewList"
}
var result = List.Retrieve(filter);
<script runat="server">
Platform.Load("core", "1");
try {
var config = {
CustomerKey: GUID(),
Name: "MyNewOldList",
Description: "This is my new list"
}
var result = List.Add(config);
Write(Stringify(result));
} catch(error) {
Write(Stringify(error));
}
</script>
[
{
"ID": 56789,
"IDSpecified": true,
"CreatedDate": "2022-12-06T13:39:23.730",
"CreatedDateSpecified": true,
"ModifiedDate": "2022-12-06T13:39:23.730",
"ModifiedDateSpecified": true,
"ListName": "MyNewList",
"Description": "This is my new list",
"Category": 12345,
"CategorySpecified": true,
"Type": "Public",
"TypeSpecified": true,
"CustomerKey": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
"Subscribers": null,
"ListClassification": "ExactTargetList",
"ListClassificationSpecified": false,
"AutomatedEmail": null,
"OptInProfile": null,
"SendClassification": null,
"Client": null,
"PartnerKey": null,
"PartnerProperties": null,
"ObjectID": null,
"Owner": null,
"CorrelationID": null,
"ObjectState": null,
"IsPlatformObject": false,
"IsPlatformObjectSpecified": false
}
]
WSProxy
var api = new Script.Util.WSProxy();
var cols = ["ListName", "ID"];
var filter = {
Property: "ListName",
SimpleOperator: "equals",
Value: "All Subscribers"
};
var result = api.retrieve("List", cols, filter);
<script runat="server">
Platform.Load("core", "1");
var api = new Script.Util.WSProxy();
try {
var cols = ["ListName", "ID"];
var filter = {
Property: "ListName",
SimpleOperator: "equals",
Value: "All Subscribers"
};
var result = api.retrieve("List", cols, filter);
Write(Stringify(result));
} catch (error) {
Write(Stringify(error));
}
</script>
{
"Status": "OK",
"RequestID": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
"Results": [
{
"ListClassification": "ExactTargetList",
"Type": "Public",
"ListName": "All Subscribers",
"Category": 0,
"Description": null,
"Subscribers": null,
"AutomatedEmail": null,
"OptInProfile": null,
"SendClassification": null,
"Client": null,
"PartnerKey": null,
"PartnerProperties": null,
"CreatedDate": "0001-01-01T00:00:00.000",
"ModifiedDate": null,
"ID": 293,
"ObjectID": null,
"CustomerKey": null,
"Owner": null,
"CorrelationID": null,
"ObjectState": null,
"IsPlatformObject": false
}
],
"HasMoreRows": false
}
TIP
Retrieve all the Lists by removing the filter property.
Reference
Ressources and references related to the current methods.
Official documentation
SOAP object