Basic Retrieves via WSProxy

The WSProxy() object offers several retrieve options, depending on the level of complexity you need. The simplest option takes the type of object as the first parameter, and an array of object property names to retrieve.

Example: Retrieve the First Page of DataExtensions 

This example returns the first page of DataExtensions without any filtering. The number of items per page varies depending on item type being requested and your account configuration.

1var prox = new Script.Util.WSProxy();
2var cols = [ "Name", "CustomerKey", "CategoryID", "IsSendable"];
3var data = prox.retrieve("DataExtension", cols);

Example Response 

The response is an object with four properties from the APIObjects SOAP items. In addition to the standard response properties, retrieved responses include the HasMoreRows property. If this property is set to true, there are more items to be returned. To retrieve the entire data set, perform one or more requests using pagination.

1{
2    "Status": "OK",
3    "RequestID": "fb768ddc-6670-4183-8b9d-4f0d5518bb2e",
4    "Results": [...],
5    "HasMoreRows": false
6}

Example: Filter the List of DataExtensions 

To filter the list of data extensions returned, add a third parameter to the function that contains a retrieve filter query. This filter specification is identical to the filter used by the SSJS Core library.

This example includes a simple filter looking for DataExtension items where the CustomerKey is “ArtistsDE”.

1var prox = new Script.Util.WSProxy();
2var cols = ["Name","CustomerKey","CategoryID","IsSendable"];
3var filter = {
4    Property: "CustomerKey",
5    SimpleOperator: "equals",
6    Value: "ArtistsDE"
7};
8var desc = prox.retrieve("DataExtension", cols, filter);

This example includes a complex filter looking for DataExtension items where the CustomerKey is “ArtistsDE” or the Name is “LikeCounter”.

1var prox = new Script.Util.WSProxy();
2var cols = ["Name","CustomerKey","CategoryID","IsSendable"];
3var filter = {
4    LeftOperand: {
5        Property: "CustomerKey",
6        SimpleOperator: "equals",
7        Value: "ArtistsDE"
8    },
9    LogicalOperator: "OR",
10    RightOperand: {
11        Property: "Name",
12        SimpleOperator: "equals",
13        Value: "LikeCounter"
14    }
15};
16var desc = prox.retrieve("DataExtension", cols, filter);

Example: Retrieve from All Accounts 

This example uses a parameter called queryAllAccounts to retrieve data from all accounts.

1var prox = new Script.Util.WSProxy();
2var queryAllAccounts = true;
3var cols = ["Name","CustomerKey","CategoryID","IsSendable"];
4var filter = {
5    Property: "CustomerKey",
6    SimpleOperator: "equals",
7    Value: "ArtistsDE"
8};
9var desc = prox.retrieve("DataExtension", cols, filter, queryAllAccounts);