Skip to main content
2 of 3
added 668 characters in body
Gortonington
  • 30.8k
  • 3
  • 27
  • 64

SSJS web API retrieve Column Names

I know this can be done via SOAP or an SDK, but I have a specific need to have this done in Marketing Cloud SSJS interacting with Web API (on a landing page, not in an email).

The aim is to create a retrieve object that pulls only the column names of a data extension and none of the values. The result should be a JSON file that only contains the column name - eg ["Email","FirstName","LastName"].

I constantly receive an error or a blank payload on each RetrieveRequest I put in. I feel like it is something small or silly that I am doing wrong.

See below for SSJS snippet I am using:

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

var DE = dataextensionIdentifier

var retrieveObject = Platform.Function.CreateObject("RetrieveRequest")

//Set the request type
Platform.Function.SetObjectProperty(retrieveObject,"ObjectType", "DataExtensionField");
    
//Set the columns
     Platform.Function.AddObjectArrayItem(retrieveObject,"Properties", "DataExtensionField.CustomerKey");
     Platform.Function.AddObjectArrayItem(retrieveObject, "Properties", "DataExtensionField.Name");

//Create a filter
var RetrieveFilter = Platform.Function.CreateObject("SimpleFilterPart");

//By CustomerKey
    Platform.Function.SetObjectProperty(RetrieveFilter, "Property", "CustomerKey")
    Platform.Function.SetObjectProperty(RetrieveFilter, "SimpleOperator","Equals")
    Platform.Function.AddObjectArrayItem(RetrieveFilter, "Value", DE )

//add filter to the retrieve
Platform.Function.SetObjectProperty(retrieveObject, "Filter", RetrieveFilter);

//Do the retrieve
var StatusAndRequestID = [0,0];

var Result = Platform.Function.InvokeRetrieve(retrieveObject,StatusAndRequestID);
Gortonington
  • 30.8k
  • 3
  • 27
  • 64