Retrieve a Data Extension record verified

Learn how to retrieve Data Extension records (rows) in Salesforce Marketing Cloud (SFMC) with SSJS (server-side JavaScript). Code snippets include WSProxy and Core methods.

Core

var customerKey = "S0M3-GU1D-K3Y-G03SR1G4T-H3R3";

var de = DataExtension.Init(customerKey);

var result = de.Rows.Retrieve({
    Property: "LastName", 
    SimpleOperator: "equals", 
    Value: "Doe" 
});
<script runat="server">

    Platform.Load("core", "1");

	try {

        var customerKey = "S0M3-GU1D-K3Y-G03SR1G4T-H3R3";

        var de = DataExtension.Init(customerKey);

        var result = de.Rows.Retrieve({
            Property: "LastName", 
            SimpleOperator: "equals", 
            Value: "Doe" 
        });

        Write(Stringify(result));
		
	} catch(error) {
        Write(Stringify(error));
    }	

</script>
[
  {
    "SubscriberKey": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
    "FirstName": "John",
    "EmailAddress": "example@mail.com",
    "LastName": "Doe"
  }
]

WSProxy

var api = new Script.Util.WSProxy();

var customerKey = "S0M3-GU1D-K3Y-G03SR1G4T-H3R3";

var result = api.retrieve(
    "DataExtensionObject[" + customerKey + "]", 
    [
        "FirstName", 
        "LastName",
        "EmailAddress"
    ]
);
<script runat="server">

    Platform.Load("core", "1");

    var api = new Script.Util.WSProxy();

	try {

        var customerKey = "S0M3-GU1D-K3Y-G03SR1G4T-H3R3";

        var result = api.retrieve(
            "DataExtensionObject[" + customerKey + "]", 
            [
                "FirstName", 
                "LastName",
                "EmailAddress"
            ]
        );

        Write(Stringify(result));
		
	} catch(error) {
        Write(Stringify(error));
    }	

</script>
{
    "Status": "OK",
    "RequestID": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
    "Results": [
        {
            "Name": null,
            "Keys": null,
            "Type": "DataExtensionObject",
            "Properties": [
                {
                    "Name": "FirstName",
                    "Value": "John"
                },
                {
                    "Name": "LastName",
                    "Value": "Doe"
                },
                {
                    "Name": "EmailAddress",
                    "Value": "example@mail.com"
                }
            ],
            "Client": null,
            "PartnerKey": null,
            "PartnerProperties": null,
            "CreatedDate": "0001-01-01T00:00:00.000",
            "ModifiedDate": null,
            "ID": 0,
            "ObjectID": null,
            "CustomerKey": null,
            "Owner": null,
            "CorrelationID": null,
            "ObjectState": null,
            "IsPlatformObject": false
        }
    ],
    "HasMoreRows": false
}

TIP

DataExtensionObject[Name] also works, unless > 36 characters.

REST API

var customerKey = "S0M3-GU1D-K3Y-G03SR1G4T-H3R3";

var endpoint = restInstanceUrl + "/data/v1/customobjectdata/key/" + customerKey + "/rowset?$pageSize=1";

var request = new Script.Util.HttpRequest(endpoint);
    request.emptyContentHandling = 0;
    request.retries = 2;
    request.continueOnError = true;
    request.setHeader("Authorization", "Bearer " + accessToken);
    request.method = "GET";
    request.contentType = "application/json";

var results = request.send();

var result = Platform.Function.ParseJSON(String(results.content));
<script runat="server">

    Platform.Load("core", "1");

    var api = new Script.Util.WSProxy();

    var restInstanceUrl = "https://YOUR_SUBDOMAIN.rest.marketingcloudapis.com/",
        accessToken     = "YOUR_REST_API_TOKEN";
	
	try {

        var customerKey = "S0M3-GU1D-K3Y-G03SR1G4T-H3R3";

        var endpoint = restInstanceUrl + "/data/v1/customobjectdata/key/" + customerKey + "/rowset?$pageSize=1";

        var request = new Script.Util.HttpRequest(endpoint);
            request.emptyContentHandling = 0;
            request.retries = 2;
            request.continueOnError = true;
            request.setHeader("Authorization", "Bearer " + accessToken);
            request.method = "GET";
            request.contentType = "application/json";

        var results = request.send();

        var result = Platform.Function.ParseJSON(String(results.content));

        Write(Stringify(result));
		
	} catch(error) {

        Write(Stringify(error));
        
    }	

</script>
{
  "links": {
    "self": "/v1/customobjectdata/token/S0M3-GU1D-K3Y-G03SR1G4T-H3R3/rowset?$page=1",
    "next": "/v1/customobjectdata/token/S0M3-GU1D-K3Y-G03SR1G4T-H3R3/rowset?$page=2"
  },
  "requestToken": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
  "tokenExpireDateUtc": "2023-02-28T19:00:00.000",
  "customObjectId": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
  "customObjectKey": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
  "pageSize": 1,
  "page": 1,
  "count": 2,
  "top": 0,
  "items": [
    {
      "keys": {
        "subscriberkey": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3"
      },
      "values": {
        "FirstName": "John",
        "LastName": "Doe",
        "EmailAddress": "example@mail.com"
      }
    }
  ]
}

WARNING

This method uses an undocumented endpoint, which can potentially be removed in the future releases.

Reference

Ressources and references related to the current methods.

Official documentation
SOAP object

Last Updated: