WS Proxy

WS-Proxy
Home Page

Mastering API Communication with WS-Proxy: A Collection of Code Snippets for Seamless Integration

Write a WS-Proxy code via SSJS to Describe SOAP Object

//Example#1

<script runat="server">
  Platform.Load("core", "1");
  try {
    var response=DescribeSoapObject("DataExtension");
    Write(Stringify(response));
  }
  catch (ex) {
    Write(ex.message + '\n');
    Write(ex.description + '\n');
    Write(ex.jintException + '\n');
  }

  function DescribeSoapObject(soapObjectname)
  {
    var api = new Script.Util.WSProxy();
    var response = api.describe(soapObjectname);
    return response;
  }
</script>

//Example#2
<script runat="server">
  Platform.Load("core", "1");
  try {
    var soapObjects=[
                       "Account"
                      ,"AccountUser"
                      ,"Authentication"
                      ,"Automation"
                      ,"BounceEvent"
                      ,"BusinessUnit"
                      ,"ClickEvent"
                      ,"ContentArea"
                      ,"DataExtension"
                      ,"DataFolder"
                      ,"Email"
                      ,"Send"
                      ,"SendClassification"
                   ]
    var response=DescribeSoapObject(soapObjects[3]);
    Write(Stringify(response));
  }
  catch (ex) {
    Write(ex.message + '\n');
    Write(ex.description + '\n');
    Write(ex.jintException + '\n');
  }

  function DescribeSoapObject(soapObjectname)
  {
    var api = new Script.Util.WSProxy();
    var response = api.describe(soapObjectname);
    return response;
  }
</script>
                                    
                                                            

Write a WS-Proxy code via SSJS to Retrieve SOAP Object

<script runat="server">
  Platform.Load("core", "1");
  try {
    var soapObjects=[
                       "Account"
                      ,"AccountUser"
                      ,"Authentication"
                      ,"Automation"
                      ,"BounceEvent"
                      ,"BusinessUnit"
                      ,"ClickEvent"
                      ,"ContentArea"
                      ,"DataExtension"
                      ,"DataFolder"
                      ,"Email"
                      ,"Send"
                      ,"SendClassification"
                   ]
    var cols = [ "Name", "CustomerKey","IsSendable"];
    var response=RetrieveSoapObject(soapObjects[8],cols);
    Write(Stringify(response));
  }
  catch (ex) {
    Write(ex.message + '\n');
    Write(ex.description + '\n');
    Write(ex.jintException + '\n');
  }

  function RetrieveSoapObject(soapObjectname,cols )
  {
    var api = new Script.Util.WSProxy();
    var response = api.retrieve(soapObjectname,cols);
    return response;
  }
</script>
                            

Write a WS-Proxy code via SSJS to Retrieve SOAP Object applying simple filter

<script runat="server">
  Platform.Load("core", "1");
  try {
    var soapObjects=[
                       "Account"
                      ,"AccountUser"
                      ,"Authentication"
                      ,"Automation"
                      ,"BounceEvent"
                      ,"BusinessUnit"
                      ,"ClickEvent"
                      ,"ContentArea"
                      ,"DataExtension"
                      ,"DataFolder"
                      ,"Email"
                      ,"Send"
                      ,"SendClassification"
                   ]
    var cols = [ "Name", "CustomerKey","IsSendable"];
    var filter=ApplyFilter("IsSendable","equals","true")
    var response=RetrieveSoapObject(soapObjects[8],cols,filter);
    Write(Stringify(response));
  }
  catch (ex) {
    Write(ex.message + '\n');
    Write(ex.description + '\n');
    Write(ex.jintException + '\n');
  }

  function RetrieveSoapObject(soapObjectname,cols,filter)
  {
    var api = new Script.Util.WSProxy();
    var response = api.retrieve(soapObjectname,cols,filter);
    return response;
  }

  function ApplyFilter(prop,operator,value)
  {
    return {
        Property: prop,
        SimpleOperator: operator,
        Value: value
    };
  }
</script>
                            

Write a WS-Proxy code via SSJS to Retrieve SOAP Object applying complex filter

<script runat="server">
  Platform.Load("core", "1");
  try {
    var soapObjects=[
                       "Account"
                      ,"AccountUser"
                      ,"Authentication"
                      ,"Automation"
                      ,"BounceEvent"
                      ,"BusinessUnit"
                      ,"ClickEvent"
                      ,"ContentArea"
                      ,"DataExtension"
                      ,"DataFolder"
                      ,"Email"
                      ,"Send"
                      ,"SendClassification"
                   ]
    var cols = [ "Name", "CustomerKey"];
    var leftOperand=ApplyFilter("CustomerKey","equals","Dataview_Bounce");
    var rightOperand=ApplyFilter("IsSendable","equals","false");
    var filter=ComplexFilter(leftOperand,"AND",rightOperand)
    var response=RetrieveSoapObject(soapObjects[8],cols,filter);
    Write(Stringify(response));
  }
  catch (ex) {
    Write(ex.message + '\n');
    Write(ex.description + '\n');
    Write(ex.jintException + '\n');
  }

  function RetrieveSoapObject(soapObjectname,cols,filter)
  {
    var api = new Script.Util.WSProxy();
    var response = api.retrieve(soapObjectname,cols,filter);
    return response;
  }

  function ApplyFilter(prop,operator,value)
  {
    return {
        Property: prop,
        SimpleOperator: operator,
        Value: value
    };
  }

  function ComplexFilter(leftOperand,logicalOperator,rightOperand)
  {
    return {
        LeftOperand: leftOperand,
        LogicalOperator:logicalOperator,
        RightOperand: rightOperand
    };
  }
</script>
                            

Write a WS-Proxy code via SSJS to Retrieve "IsRetrievable" properties for a SOAP Object

<script runat="server">
  Platform.Load("core", "1");
try {
  // Set the name of the SOAP object to "DataExtension".
  var soapObject = "DataExtension";

  // Call the function 'DescribeSoapObject' to retrieve the metadata information for the SOAP object.
  var describeResponse = DescribeSoapObject(soapObject);

  // Extract the properties array from the describeResponse.
  var properties = describeResponse.Results[0].Properties;

  // Call the function 'FetchRetrieveableProperties' to get an array of retrieveable property names.
  var cols = FetchRetrieveableProperties(properties);

  // Apply a filter for the SOAP object, where the "CustomerKey" property equals "Dataview_Bounce".
  var filter = ApplyFilter("CustomerKey", "equals", "Dataview_Bounce");

  // Call the function 'RetrieveSoapObject' to retrieve data from the SOAP object using the specified filter and columns.
  var response = RetrieveSoapObject(soapObject, cols, filter);

  // Convert the response object to a string representation and write it to the output.
  Write(Stringify(response));
}
catch (ex) {
  // If an exception occurs during the execution, catch it and write the error messages to the output.
  Write(ex.message + '\n');
  Write(ex.description + '\n');
  Write(ex.jintException + '\n');
}


// Function to describe a SOAP object using WSProxy.
// Parameters:
// - soapObjectname: The name of the SOAP object to describe.

function DescribeSoapObject(soapObjectname) {
  // Create a new instance of WSProxy to interact with the SOAP API.
  var api = new Script.Util.WSProxy();

  // Call the describe method of WSProxy to fetch the metadata information for the SOAP object.
  var response = api.describe(soapObjectname);

  // Return the response, which contains the metadata information for the SOAP object.
  return response;
}

  
// Function to fetch an array of retrieveable property names from SOAP metadata.
// Parameters:
// - soapMetaData: An array of objects containing metadata information for SOAP properties.

function FetchRetrieveableProperties(soapMetaData) {
  // Create an empty array to store the names of retrieveable properties.
  var propertiesName = [];

  // Iterate through each object in the soapMetaData array.
  for (var i in soapMetaData) {
    // Extract the 'Name' property from the current object and store it in the propertiesName array.
    var name = soapMetaData[i].Name;
    var isRetrievable=soapMetaData[i].IsRetrievable
    if(isRetrievable===true)
       propertiesName.push(name);
  }

  // Return the array containing the names of retrieveable properties.
  return propertiesName;
}


// Function to create a filter object for data retrieval or processing.
// Parameters:
// - prop: The property name to filter on.
// - operator: The operator used for filtering (e.g., equals, greater than, less than, etc.).
// - value: The value to compare the property against.

function ApplyFilter(prop, operator, value) {
  // Create and return a filter object with the specified properties.
  return {
    Property: prop,         // The property name on which the filter is applied.
    SimpleOperator: operator, // The operator used for the filter (e.g., 'equals', 'greaterThan', etc.).
    Value: value            // The value to compare the property against.
  };
}


// Function to retrieve data from a SOAP object using WSProxy.
// Parameters:
// - soapObjectname: The name of the SOAP object from which data will be retrieved.
// - cols: An array of column names to retrieve from the SOAP object.
// - filter: A filter to apply when querying the SOAP object (optional).

function RetrieveSoapObject(soapObjectname, cols, filter) {
  // Create a new instance of WSProxy to interact with the SOAP object.
  var api = new Script.Util.WSProxy();

  // Call the retrieve method of WSProxy to fetch data from the SOAP object.
  var response = api.retrieve(soapObjectname, cols, filter);

  // Return the response, which contains the retrieved data from the SOAP object.
  return response;
}

  
</script>
                            

Write a WS-Proxy code via SSJS to Retrieve "Overwrite" Query Definitions

 <script runat="server">
  Platform.Load("core", "1");
try {
  // Set the name of the SOAP object to "DataExtension".
  var soapObject = "QueryDefinition";

  // Call the function 'DescribeSoapObject' to retrieve the metadata information for the SOAP object.
  var describeResponse = DescribeSoapObject(soapObject);

  // Extract the properties array from the describeResponse.
  var properties = describeResponse.Results[0].Properties;

  // Call the function 'FetchRetrieveableProperties' to get an array of retrieveable property names.
  var cols = FetchRetrieveableProperties(properties);

  // Apply a filter for the SOAP object, where the "TargetUpdateType" property equals "Overwrite".
  var filter = ApplyFilter("TargetUpdateType", "equals", "Overwrite");

  // Call the function 'RetrieveSoapObject' to retrieve data from the SOAP object using the specified filter and columns.
  var response = RetrieveSoapObject(soapObject, cols, filter);

  // Convert the response object to a string representation and write it to the output.
  Write(response.Results.length);
}
catch (ex) {
  // If an exception occurs during the execution, catch it and write the error messages to the output.
  Write(ex.message + '\n');
  Write(ex.description + '\n');
  Write(ex.jintException + '\n');
}


// Function to describe a SOAP object using WSProxy.
// Parameters:
// - soapObjectname: The name of the SOAP object to describe.

function DescribeSoapObject(soapObjectname) {
  // Create a new instance of WSProxy to interact with the SOAP API.
  var api = new Script.Util.WSProxy();

  // Call the describe method of WSProxy to fetch the metadata information for the SOAP object.
  var response = api.describe(soapObjectname);

  // Return the response, which contains the metadata information for the SOAP object.
  return response;
}

  
// Function to fetch an array of retrieveable property names from SOAP metadata.
// Parameters:
// - soapMetaData: An array of objects containing metadata information for SOAP properties.

function FetchRetrieveableProperties(soapMetaData) {
  // Create an empty array to store the names of retrieveable properties.
  var propertiesName = [];

  // Iterate through each object in the soapMetaData array.
  for (var i in soapMetaData) {
    // Extract the 'Name' property from the current object and store it in the propertiesName array.
    var name = soapMetaData[i].Name;
    var isRetrievable=soapMetaData[i].IsRetrievable
    if(isRetrievable===true)
       propertiesName.push(name);
  }

  // Return the array containing the names of retrieveable properties.
  return propertiesName;
}


// Function to create a filter object for data retrieval or processing.
// Parameters:
// - prop: The property name to filter on.
// - operator: The operator used for filtering (e.g., equals, greater than, less than, etc.).
// - value: The value to compare the property against.

function ApplyFilter(prop, operator, value) {
  // Create and return a filter object with the specified properties.
  return {
    Property: prop,         // The property name on which the filter is applied.
    SimpleOperator: operator, // The operator used for the filter (e.g., 'equals', 'greaterThan', etc.).
    Value: value            // The value to compare the property against.
  };
}


// Function to retrieve data from a SOAP object using WSProxy.
// Parameters:
// - soapObjectname: The name of the SOAP object from which data will be retrieved.
// - cols: An array of column names to retrieve from the SOAP object.
// - filter: A filter to apply when querying the SOAP object (optional).

function RetrieveSoapObject(soapObjectname, cols, filter) {
  // Create a new instance of WSProxy to interact with the SOAP object.
  var api = new Script.Util.WSProxy();

  // Call the retrieve method of WSProxy to fetch data from the SOAP object.
  var response = api.retrieve(soapObjectname, cols, filter);

  // Return the response, which contains the retrieved data from the SOAP object.
  return response;
}

  
</script>
                            

Write a WS-Proxy code via SSJS to Retrieve "Sendable" Data Extension

<script runat="server">
  Platform.Load("core", "1");
try {
  // Set the name of the SOAP object to "DataExtension".
  var soapObject = "DataExtension";

  // Call the function 'DescribeSoapObject' to retrieve the metadata information for the SOAP object.
  var describeResponse = DescribeSoapObject(soapObject);

  // Extract the properties array from the describeResponse.
  var properties = describeResponse.Results[0].Properties;

  // Call the function 'FetchRetrieveableProperties' to get an array of retrieveable property names.
  var cols = FetchRetrieveableProperties(properties);

  // Apply a filter for the SOAP object, where the "IsSendable" property equals "true".
  var filter = ApplyFilter("IsSendable", "equals", "true");

  // Call the function 'RetrieveSoapObject' to retrieve data from the SOAP object using the specified filter and columns.
  var response = RetrieveSoapObject(soapObject, cols, filter);

  // Convert the response object to a string representation and write it to the output.
  Write(response.Results.length);
}
catch (ex) {
  // If an exception occurs during the execution, catch it and write the error messages to the output.
  Write(ex.message + '\n');
  Write(ex.description + '\n');
  Write(ex.jintException + '\n');
}


// Function to describe a SOAP object using WSProxy.
// Parameters:
// - soapObjectname: The name of the SOAP object to describe.

function DescribeSoapObject(soapObjectname) {
  // Create a new instance of WSProxy to interact with the SOAP API.
  var api = new Script.Util.WSProxy();

  // Call the describe method of WSProxy to fetch the metadata information for the SOAP object.
  var response = api.describe(soapObjectname);

  // Return the response, which contains the metadata information for the SOAP object.
  return response;
}

  
// Function to fetch an array of retrieveable property names from SOAP metadata.
// Parameters:
// - soapMetaData: An array of objects containing metadata information for SOAP properties.

function FetchRetrieveableProperties(soapMetaData) {
  // Create an empty array to store the names of retrieveable properties.
  var propertiesName = [];

  // Iterate through each object in the soapMetaData array.
  for (var i in soapMetaData) {
    // Extract the 'Name' property from the current object and store it in the propertiesName array.
    var name = soapMetaData[i].Name;
    var isRetrievable=soapMetaData[i].IsRetrievable
    if(isRetrievable===true)
       propertiesName.push(name);
  }

  // Return the array containing the names of retrieveable properties.
  return propertiesName;
}


// Function to create a filter object for data retrieval or processing.
// Parameters:
// - prop: The property name to filter on.
// - operator: The operator used for filtering (e.g., equals, greater than, less than, etc.).
// - value: The value to compare the property against.

function ApplyFilter(prop, operator, value) {
  // Create and return a filter object with the specified properties.
  return {
    Property: prop,         // The property name on which the filter is applied.
    SimpleOperator: operator, // The operator used for the filter (e.g., 'equals', 'greaterThan', etc.).
    Value: value            // The value to compare the property against.
  };
}


// Function to retrieve data from a SOAP object using WSProxy.
// Parameters:
// - soapObjectname: The name of the SOAP object from which data will be retrieved.
// - cols: An array of column names to retrieve from the SOAP object.
// - filter: A filter to apply when querying the SOAP object (optional).

function RetrieveSoapObject(soapObjectname, cols, filter) {
  // Create a new instance of WSProxy to interact with the SOAP object.
  var api = new Script.Util.WSProxy();

  // Call the retrieve method of WSProxy to fetch data from the SOAP object.
  var response = api.retrieve(soapObjectname, cols, filter);

  // Return the response, which contains the retrieved data from the SOAP object.
  return response;
}

  
</script>
                            

Write a WS-Proxy code via SSJS to Retrieve Autoamtion in "Ready" status

<script runat="server">
  Platform.Load("core", "1");
try {
  // Set the name of the SOAP object to "DataExtension".
  var soapObject = "Automation";

  // Call the function 'DescribeSoapObject' to retrieve the metadata information for the SOAP object.
  var describeResponse = DescribeSoapObject(soapObject);

  // Extract the properties array from the describeResponse.
  var properties = describeResponse.Results[0].Properties;

  // Call the function 'FetchRetrieveableProperties' to get an array of retrieveable property names.
  var cols = FetchRetrieveableProperties(properties);

  // Apply a filter for the SOAP object, where the "Status" property equals "Ready".
  var filter = ApplyFilter("Status", "equals", "2");

  // Call the function 'RetrieveSoapObject' to retrieve data from the SOAP object using the specified filter and columns.
  var response = RetrieveSoapObject(soapObject, cols, filter);

  // Convert the response object to a string representation and write it to the output.
  Write("There are "+response.Results.length + " Automation(s) in Ready status \n");
  Write("\n");
  Write ("Below are the customer keys for those automations : \n")
  for (var i in response.Results)
    Write(response.Results[i].CustomerKey +'\n');
  
}
catch (ex) {
  // If an exception occurs during the execution, catch it and write the error messages to the output.
  Write(ex.message + '\n');
  Write(ex.description + '\n');
  Write(ex.jintException + '\n');
}


// Function to describe a SOAP object using WSProxy.
// Parameters:
// - soapObjectname: The name of the SOAP object to describe.

function DescribeSoapObject(soapObjectname) {
  // Create a new instance of WSProxy to interact with the SOAP API.
  var api = new Script.Util.WSProxy();

  // Call the describe method of WSProxy to fetch the metadata information for the SOAP object.
  var response = api.describe(soapObjectname);

  // Return the response, which contains the metadata information for the SOAP object.
  return response;
}

  
// Function to fetch an array of retrieveable property names from SOAP metadata.
// Parameters:
// - soapMetaData: An array of objects containing metadata information for SOAP properties.

function FetchRetrieveableProperties(soapMetaData) {
  // Create an empty array to store the names of retrieveable properties.
  var propertiesName = [];

  // Iterate through each object in the soapMetaData array.
  for (var i in soapMetaData) {
    // Extract the 'Name' property from the current object and store it in the propertiesName array.
    var name = soapMetaData[i].Name;
    var isRetrievable=soapMetaData[i].IsRetrievable
    if(isRetrievable===true)
       propertiesName.push(name);
  }

  // Return the array containing the names of retrieveable properties.
  return propertiesName;
}


// Function to create a filter object for data retrieval or processing.
// Parameters:
// - prop: The property name to filter on.
// - operator: The operator used for filtering (e.g., equals, greater than, less than, etc.).
// - value: The value to compare the property against.

function ApplyFilter(prop, operator, value) {
  // Create and return a filter object with the specified properties.
  return {
    Property: prop,         // The property name on which the filter is applied.
    SimpleOperator: operator, // The operator used for the filter (e.g., 'equals', 'greaterThan', etc.).
    Value: value            // The value to compare the property against.
  };
}


// Function to retrieve data from a SOAP object using WSProxy.
// Parameters:
// - soapObjectname: The name of the SOAP object from which data will be retrieved.
// - cols: An array of column names to retrieve from the SOAP object.
// - filter: A filter to apply when querying the SOAP object (optional).

function RetrieveSoapObject(soapObjectname, cols, filter) {
  // Create a new instance of WSProxy to interact with the SOAP object.
  var api = new Script.Util.WSProxy();

  // Call the retrieve method of WSProxy to fetch data from the SOAP object.
  var response = api.retrieve(soapObjectname, cols, filter);

  // Return the response, which contains the retrieved data from the SOAP object.
  return response;
}

  
</script>
                            

Write a WS-Proxy code via SSJS to Start/Stop an Autoamtion

<script runat="server">
  Platform.Load("core", "1");
try {
  // Set the name of the SOAP object to "Automation".
  var soapObject = "Automation";

  // Call the function 'DescribeSoapObject' to retrieve the metadata information for the SOAP object.
  var describeResponse = DescribeSoapObject(soapObject);

  // Extract the properties array from the describeResponse.
  var properties = describeResponse.Results[0].Properties;

  // Call the function 'FetchRetrieveableProperties' to get an array of retrieveable property names.
  var cols = FetchRetrieveableProperties(properties);

  // Apply a filter for the SOAP object, where the "CustomerKey" property equals "Dataview_Bounce".
  var filter = ApplyFilter("Name", "equals", "Holidays Calculations");

  // Call the function 'RetrieveSoapObject' to retrieve data from the SOAP object using the specified filter and columns.
  var response = RetrieveSoapObject(soapObject, cols, filter);

  var result=performItemSoapObject(soapObject,response)

  // Convert the response object to a string representation and write it to the output.
  Write(Stringify(result));

}
catch (ex) {
  // If an exception occurs during the execution, catch it and write the error messages to the output.
  Write(ex.message + '\n');
  Write(ex.description + '\n');
  Write(ex.jintException + '\n');
}


// Function to describe a SOAP object using WSProxy.
// Parameters:
// - soapObjectname: The name of the SOAP object to describe.

function DescribeSoapObject(soapObjectname) {
  // Create a new instance of WSProxy to interact with the SOAP API.
  var api = new Script.Util.WSProxy();

  // Call the describe method of WSProxy to fetch the metadata information for the SOAP object.
  var response = api.describe(soapObjectname);

  // Return the response, which contains the metadata information for the SOAP object.
  return response;
}

  
// Function to fetch an array of retrieveable property names from SOAP metadata.
// Parameters:
// - soapMetaData: An array of objects containing metadata information for SOAP properties.

function FetchRetrieveableProperties(soapMetaData) {
  // Create an empty array to store the names of retrieveable properties.
  var propertiesName = [];

  // Iterate through each object in the soapMetaData array.
  for (var i in soapMetaData) {
    // Extract the 'Name' property from the current object and store it in the propertiesName array.
    var name = soapMetaData[i].Name;
    var isRetrievable=soapMetaData[i].IsRetrievable
    if(isRetrievable===true)
       propertiesName.push(name);
  }

  // Return the array containing the names of retrieveable properties.
  return propertiesName;
}


// Function to create a filter object for data retrieval or processing.
// Parameters:
// - prop: The property name to filter on.
// - operator: The operator used for filtering (e.g., equals, greater than, less than, etc.).
// - value: The value to compare the property against.

function ApplyFilter(prop, operator, value) {
  // Create and return a filter object with the specified properties.
  return {
    Property: prop,         // The property name on which the filter is applied.
    SimpleOperator: operator, // The operator used for the filter (e.g., 'equals', 'greaterThan', etc.).
    Value: value            // The value to compare the property against.
  };
}


// Function to retrieve data from a SOAP object using WSProxy.
// Parameters:
// - soapObjectname: The name of the SOAP object from which data will be retrieved.
// - cols: An array of column names to retrieve from the SOAP object.
// - filter: A filter to apply when querying the SOAP object (optional).

function RetrieveSoapObject(soapObjectname, cols, filter) {
  // Create a new instance of WSProxy to interact with the SOAP object.
  var api = new Script.Util.WSProxy();

  // Call the retrieve method of WSProxy to fetch data from the SOAP object.
  var response = api.retrieve(soapObjectname, cols, filter);

  // Return the response, which contains the retrieved data from the SOAP object.
  return response;
}

// Function to perform operation on a SOAP object using WSProxy.
// Parameters:
// - soapObjectname: The name of the SOAP object from which data will be retrieved.
// - cols: An array of column names to retrieve from the SOAP object.
// - filter: A filter to apply when querying the SOAP object (optional).
function performItemSoapObject(soapObjectname,payload)
{
  // Create a new instance of WSProxy to interact with the SOAP object.
  var api = new Script.Util.WSProxy();
  api.setClientId({
    "ID": Platform.Function.AuthenticatedMemberID(),
    "UserID": Platform.Function.AuthenticatedEmployeeID()
});
  var customerKey = payload.Results[0].CustomerKey;
  var filter = { "CustomerKey": customerKey};
  var action = ["start", "stop"];
  var opts = {};
  var result = api.performItem(soapObjectname, filter, action[1], opts);
  return result;
}
  
</script>
                            

Write a WS-Proxy code via SSJS to Delete an Autoamtion

 <script runat="server">
  Platform.Load("core", "1");
try {
  // Set the name of the SOAP object to "Automation".
  var soapObject = "Automation";

  // Call the function 'DescribeSoapObject' to retrieve the metadata information for the SOAP object.
  var describeResponse = DescribeSoapObject(soapObject);

  // Extract the properties array from the describeResponse.
  var properties = describeResponse.Results[0].Properties;

  // Call the function 'FetchRetrieveableProperties' to get an array of retrieveable property names.
  var cols = FetchRetrieveableProperties(properties);

  // Apply a filter for the SOAP object, where the "Name" property equals "Demo 1".
  var filter = ApplyFilter("Name", "equals", "Demo 1");

  // Call the function 'RetrieveSoapObject' to retrieve data from the SOAP object using the specified filter and columns.
  var response = RetrieveSoapObject(soapObject, cols, filter);

  var result=DeleteItemSoapObject(soapObject,response)

  // Convert the response object to a string representation and write it to the output.
  Write(Stringify(result));

}
catch (ex) {
  // If an exception occurs during the execution, catch it and write the error messages to the output.
  Write(ex.message + '\n');
  Write(ex.description + '\n');
  Write(ex.jintException + '\n');
}


// Function to describe a SOAP object using WSProxy.
// Parameters:
// - soapObjectname: The name of the SOAP object to describe.

function DescribeSoapObject(soapObjectname) {
  // Create a new instance of WSProxy to interact with the SOAP API.
  var api = new Script.Util.WSProxy();

  // Call the describe method of WSProxy to fetch the metadata information for the SOAP object.
  var response = api.describe(soapObjectname);

  // Return the response, which contains the metadata information for the SOAP object.
  return response;
}

  
// Function to fetch an array of retrieveable property names from SOAP metadata.
// Parameters:
// - soapMetaData: An array of objects containing metadata information for SOAP properties.

function FetchRetrieveableProperties(soapMetaData) {
  // Create an empty array to store the names of retrieveable properties.
  var propertiesName = [];

  // Iterate through each object in the soapMetaData array.
  for (var i in soapMetaData) {
    // Extract the 'Name' property from the current object and store it in the propertiesName array.
    var name = soapMetaData[i].Name;
    var isRetrievable=soapMetaData[i].IsRetrievable
    if(isRetrievable===true)
       propertiesName.push(name);
  }

  // Return the array containing the names of retrieveable properties.
  return propertiesName;
}


// Function to create a filter object for data retrieval or processing.
// Parameters:
// - prop: The property name to filter on.
// - operator: The operator used for filtering (e.g., equals, greater than, less than, etc.).
// - value: The value to compare the property against.

function ApplyFilter(prop, operator, value) {
  // Create and return a filter object with the specified properties.
  return {
    Property: prop,         // The property name on which the filter is applied.
    SimpleOperator: operator, // The operator used for the filter (e.g., 'equals', 'greaterThan', etc.).
    Value: value            // The value to compare the property against.
  };
}


// Function to retrieve data from a SOAP object using WSProxy.
// Parameters:
// - soapObjectname: The name of the SOAP object from which data will be retrieved.
// - cols: An array of column names to retrieve from the SOAP object.
// - filter: A filter to apply when querying the SOAP object (optional).

function RetrieveSoapObject(soapObjectname, cols, filter) {
  // Create a new instance of WSProxy to interact with the SOAP object.
  var api = new Script.Util.WSProxy();

  // Call the retrieve method of WSProxy to fetch data from the SOAP object.
  var response = api.retrieve(soapObjectname, cols, filter);

  // Return the response, which contains the retrieved data from the SOAP object.
  return response;
}

// Function to delete  a SOAP object using WSProxy.
// Parameters:
// - soapObjectname: The name of the SOAP object from which data will be retrieved.
// - cols: An array of column names to retrieve from the SOAP object.
// - filter: A filter to apply when querying the SOAP object (optional).
function DeleteItemSoapObject(soapObjectname,payload)
{
  // Create a new instance of WSProxy to interact with the SOAP object.
  var api = new Script.Util.WSProxy();
  api.setClientId({
    "ID": Platform.Function.AuthenticatedMemberID(),
    "UserID": Platform.Function.AuthenticatedEmployeeID()
});
  var customerKey = payload.Results[0].CustomerKey;
  var filter = { "CustomerKey": customerKey};
  var result = api.deleteItem(soapObjectname, filter);
  return result;
}
  
</script>
                            

Write a WS-Proxy code via SSJS to Create a Data Extension

 <script runat="server">
  Platform.Load("core", "1");
  function createDataExtension(dataExtensionName) {
    var api = new Script.Util.WSProxy();
    api.setClientId({
      "ID": Platform.Function.AuthenticatedMemberID()
    }
                   );
    var config = {
      "CustomerKey": String(Platform.Function.GUID()).toUpperCase(),
      "Name": dataExtensionName,
      "CategoryID": 5017,
      "Fields": [
        {
          "Name": "FirstName",
          "FieldType": "Text",
          "MaxLength": 50
        }
        ,
        {
          "Name": "LastName",
          "FieldType": "Text",
          "MaxLength": 80
        }
        , 
        {
          "Name": "SubscriberKey",
          "FieldType": "Text",
          "MaxLength": 254,
          "IsPrimaryKey": true,
          "IsRequired" : true
        }
        ,
        {
          "Name": "EmailAddress",
          "FieldType": "EmailAddress",
          "IsRequired" : true
        }
      ],
      "DataRetentionPeriodLength": 4,
      "RowBasedRetention": false,
      "ResetRetentionPeriodOnImport": true,
      "DeleteAtEndOfRetentionPeriod": false,
      "DataRetentionPeriod": "Weeks"
    };
    var result = api.createItem("DataExtension", config);
    return(Stringify(result));
  };
  var result=createDataExtension("My Data Extension")
  Write(result);
</script>

// NOTE : LINE 12 CATEGORY ID NEEDS TO BE DEFINED AND HAS TO BE PRESENT
                            

Write a WS-Proxy code via SSJS to retrieve category ID

<script runat="server" language="javascript">
  Platform.Load("core", "1");
  var prox = new Script.Util.WSProxy();
  try{
    var req = prox.retrieve("DataExtension", ["ObjectID"], {
      Property: "DataExtension.CustomerKey",
      SimpleOperator: "equals",
      Value: 'ED3C2389-8087-488E-AA68-61D9E57F50FD'
    }
                          );
    var objectId = req.Results[0].ObjectID;
    Write(objectId);
  }
  catch(e){
    Write(e.message)}
</script>
                            

Write a WS-Proxy code via SSJS to rename a data extension

<script runat="server" language="javascript">
    Platform.Load("core", "1");
    try{
    var prox = new Script.Util.WSProxy();
    var objectID = "38a2e7a6-3e2c-ed11-b858-f40343bf8bc8";
    var name = "Renamed DE";
    var res = prox.updateItem("DataExtension", {
        "ObjectID":objectID, "Name":name }
    );
    Write(Stringify(res));
  }
    catch(e){
        Write(e.message)}
</script>
                            

Write a WS-Proxy code via SSJS to update a record in a data extension

<script runat="server" language="javascript">
  Platform.Load("core", "1");
  try{
    var api = new Script.Util.WSProxy();
    /* Build DE Object */
    var updateObject = {
      CustomerKey: 'My Data Extension',
      Properties: [
        {
          Name: 'FirstName',
          Value: 'Tester'
        }
        ,
        {
          Name: 'LastName',
          Value: 'Testerson'
        }
        ,
        {
          Name: 'SubscriberKey',
          Value: 'b2.shashi@gmail.com'
        }
        ,
        {
          Name: 'EmailAddress',
          Value: 'b2.shashi@gmail.com'
        }
      ]
    };
    var options = {
      SaveOptions: [{
        'PropertyName': '*', SaveAction: 'UpdateAdd'}
                   ]};
    var res = api.updateItem('DataExtensionObject', updateObject, options);
    Write(Stringify(res));
  }
  catch(e){
    Write(e.message)}
</script>

                            

Write a WS-Proxy code via SSJS to delete a data extension

 <script runat="server" language="javascript">
    Platform.Load("core", "1");
    try{
    var prox = new Script.Util.WSProxy();
    var objectID = '38a2e7a6-3e2c-ed11-b858-f40343bf8bc8';
    var res = prox.deleteItem("DataExtension", {
        "ObjectID":objectID }
    );
    Write(Stringify(res));
  }
    catch(e){
        Write(e.message)}
</script>

                            

Write a WS-Proxy code via SSJS to retrieve a data extension from all the BU

<script runat="server" language="javascript">
    Platform.Load("core", "1");
    var prox = new Script.Util.WSProxy();
    var props = {QueryAllAccounts: true };
    var cols = ["Name","CustomerKey","CategoryID","IsSendable"];
    var filter = {
    Property: "CustomerKey",
    SimpleOperator: "equals",
    Value: MY-DE
};
    var opts = {
        BatchSize: 25
};
    var data = prox.retrieve("DataExtension", cols,filter,opts );
    Write(Stringify(data.Results));
</script>
                            

Write a WS-Proxy code via SSJS to perform email content check

<script runat="server" language="javascript">
    Platform.Load("core", "1");
    try{
    var prox = new Script.Util.WSProxy();
    var action = "Start";
    var props = {
        Email: {
        ID: 12345
      }
    };
    var opts = {
    };
    var data = prox.performItem("EmailContentCheck", props, action, opts);
    Write(Stringify(data));
  }
    catch(e)
    {
        Write(e.message);
  }
</script>
                            

Write a WS-Proxy code via SSJS to retrieve Business Unit details

<script runat="server">
    Platform.Load("core","1");
    try{
        Write('\n Send Classification :\n');
    var cols = ["Name","CreatedDate","ModifiedDate","Description"];
    var prox = new Script.Util.WSProxy();
    var res = prox.retrieve("SendClassification", cols);
    Write(Stringify(res.Results[0]));
    Write('\n');
    Write('\n Sender Profile :\n');
    var cols = ["Name","CreatedDate","ModifiedDate"
,"Description","FromName","FromAddress","UseDefaultRMMRules"
,"AutoForwardToEmailAddress","AutoForwardToName","DirectForward"];
    var prox = new Script.Util.WSProxy();
    var res = prox.retrieve("SenderProfile", cols);
    Write(Stringify(res.Results[0]));
    Write('\n');
    Write('\n Delivery Profile :\n' );
    var cols = ["Name","CreatedDate","ModifiedDate","Description"
,"FromName","FromAddress"];
    var prox = new Script.Util.WSProxy();
    var res = prox.retrieve("SenderProfile", cols);
    Write(Stringify(res.Results[0]));
    Write('\n');
    Write('\n Business Unit :\n' );
    var cols = ["Name"];
    var prox = new Script.Util.WSProxy();
    var res = prox.retrieve("BusinessUnit", cols);
    Write(Stringify(res));
    Write('\n');
    Write('\n Account User :\n' );
    var cols = ["Name"];
    var prox = new Script.Util.WSProxy();
    var res = prox.retrieve("AccountUser", cols);
    Write(Stringify(res));
    Write('\n');
    Write('\n Certificate :\n' );
    var cols = ["Client"];
    var prox = new Script.Util.WSProxy();
    var res = prox.retrieve("Certificate", cols);
    Write(Stringify(res));
    Write('\n');
    Write('\n Email :\n' );
    var cols = ["CategoryID","Name"];
    var prox = new Script.Util.WSProxy();
    var res = prox.retrieve("Email", cols);
    Write(Stringify(res));
    Write('\n');
    Write('\n Message :\n' );
    var cols = ["CreatedDate"];
    var prox = new Script.Util.WSProxy();
    var res = prox.retrieve("Message", cols);
    Write(Stringify(res));
    Write('\n');
    Write('\n UnsubscribeFromSMSPublicationMOKeyword :\n' );
    var cols = ["AllUnsubSuccessMessage"];
    var prox = new Script.Util.WSProxy();
    var res = prox.retrieve("UnsubscribeFromSMSPublicationMOKeyword", cols);
    Write(Stringify(res));
    Write('\n');
    Write('\n SendSMSMOKeyword :\n' );
    var cols = ["CustomerKey"];
    var prox = new Script.Util.WSProxy();
    var res = prox.retrieve("SendSMSMOKeyword", cols);
    Write(Stringify(res));
    Write('\n');
  }
    catch(ex)
    {
        Write(ex.message);
  }
</script>
                            

Write a WS-Proxy code via SSJS to retrieve last 30 days sends

 
<script runat="server">
    Platform.Load("core","1");
    try{
    var last30Days = new Date();
    last30Days.setDate(last30Days.getDate() - 30);
    var cols = [
    "ID","SendDate","UniqueClicks","UniqueOpens"
    ,"Unsubscribes","NumberDelivered"
    ,"NumberTargeted","ForwardedEmails"
    ,"EmailName","Status","Duplicates"
    ,"InvalidAddresses","Subject"
    ,"NumberErrored","SendWindowOpen","SendWindowClose"
    ,"IsAlwaysOn","FromAddress","FromName"
    ,"CreatedDate","ModifiedDate"];
    var prox = new Script.Util.WSProxy();
    filter = {
        Property:"ModifiedDate", SimpleOperator:"greaterThan", Value: last30Days }
    var res = prox.retrieve("Send", cols,filter);
    Write('\n')
    if(res.Results && res.Results.length > 0) {
      for (var i=0;i<res.Results.length; i++)
    {
        Write(res.Results[i].ID + '|');
    Write( res.Results[i].SendDate +'|');
    Write( res.Results[i].UniqueClicks +'|');
    Write( res.Results[i].UniqueOpens +'|');
    Write( res.Results[i].Unsubscribes +'|');
    Write( res.Results[i].NumberDelivered +'|');
    Write( res.Results[i].NumberTargeted +'|');
    Write( res.Results[i].EmailName +'|');
    Write( res.Results[i].Duplicates +'|');
    Write( res.Results[i].InvalidAddresses +'|');
    Write('\n')
      }
    }
  }
    catch(ex)
    {
        Write(ex.message);
  }
</script>
                            

Write a WS-Proxy code via SSJS to retrieve data extension with HasMoreRows & GetNextBatch Function

 
<script runat="server">
  Platform.Load("core", "1.1.1");
  var config = {
    name: "Veeva",
    cols: ["Email", "Country", "City", "Gender"],
    filter:  {
      LeftOperand:{
        Property:"Consent_Status",
        SimpleOperator: "isNotNull",
        Value: " "
      }
      ,
      LogicalOperator:"AND",
      RightOperand:{
        Property:"Last_Name",
        SimpleOperator:"isNotNull",
        Value:" "
      }
    }
  }
  var records = retrieveRecords(config);
  Write(Stringify(records));
  function retrieveRecords(config) {
    var prox = new Script.Util.WSProxy();
    var records = [],
        moreData = true,
        reqID = data = null;
    while (moreData) {
      moreData = false;
      if (reqID == null) {
        data = prox.retrieve("DataExtensionObject[" + config.name + "]", 
config.cols, config.filter);
      }
      else {
        data = prox.getNextBatch("DataExtensionObject[" + config.name + "]", reqID);
      }
      if (data != null) {
        moreData = data.HasMoreRows;
        reqID = data.RequestID;
        for (var i = 0; i < data.Results.length; i++) {
          var result_list = data.Results[i].Properties;
          var obj = {
          };
          for (k in result_list) {
            var key = result_list[k].Name;
            var val = result_list[k].Value
            if (key.indexOf("_") != 0) obj[key] = val;
          }
          records.push(obj);
        }
      }
    }
    return records;
  }
</script>
                            

Write a WS-Proxy code via SSJS to retrieve not sent event

  <script runat="server">
  Platform.Load("core","1");
  try{
    var cols = [
                "BatchID",
                "EventDate",
                "SendID",
                "SubscriberKey",
                "EventType",
                "TriggeredSendDefinitionObjectID"
                ];
    var prox = new Script.Util.WSProxy();
    var filterNull = {
      Property: "TriggeredSendDefinitionObjectID",
      SimpleOperator: "isNull",
      Value: ''
    };
    var filterNotNull = {
      Property: "TriggeredSendDefinitionObjectID",
      SimpleOperator: "isNotNull",
      Value: ''
    };
    var res = prox.retrieve("NotSentEvent", cols,filterNotNull);
    Write(Stringify(res.Results));
  }
  catch(ex)
  {
    Write(ex.message);
  }
</script>
                            

Write a WS-Proxy code via SSJS to rename and add additional attribute to a DataExtension

  <script runat="server">
    Platform.Load("core", "1");
    try{
        function updateDataExtension(dataExtensionName, CustomerKey) {
            var api = new Script.Util.WSProxy();
            api.setClientId({
                "ID": Platform.Function.AuthenticatedMemberID()
            }
            );

            var req = api.retrieve("DataExtension", ["ObjectID"], {
                Property: "DataExtension.CustomerKey",
                SimpleOperator: "equals",
                Value: CustomerKey
            }
            );
            var objectId = req.Results[0].ObjectID;
            var config = {
                "ObjectID": objectId,
                "Name": dataExtensionName,
                "Fields": [{
                    "Name": "Address5",
                    "FieldType": "Text",
                    "MaxLength": 200
                }]
            };
            var result = api.updateItem("DataExtension", config);
            return (Stringify(result));
        };
    var result=updateDataExtension("Renamed DE","DEExternalKey")
    Write(result);
  }
    catch(e){
        Write(e.message)}
</script>
                            

Write a WS-Proxy code via SSJS to retrieve Trigger Send summary

  <script runat="server" language="javascript">
    Platform.Load("core", "1");
    try{
    var prox = new Script.Util.WSProxy();
    var cols = ["Sent","CustomerKey",
    "Bounces","Clicks","NotSentDueToOptOut",
    "NotSentDueToUndeliverable","NotSentDueToError",
    "OptOuts","InProcess","Queued","UniqueOpens",
    "UniqueOpens","Conversions"
    ];
    prox.setClientId({
        "ID": Platform.Function.AuthenticatedMemberID()
    }
    );
    var filter = {
        Property: "CustomerKey",
    SimpleOperator: "equals",
    Value: 113388
    };
    var data = prox.retrieve("TriggeredSendSummary", cols,filter);
    if(data.Results && data.Results.length > 0) {
      for (var i=0;i<data.Results.length; i++)
    {
        Write("Sent : " + data.Results[i].Sent + '\n');
    Write("NotSentDueToError : " +  data.Results[i].NotSentDueToError + '\n');
    Write("Bounces : " +  data.Results[i].Bounces + '\n');
    Write("NotSentDueToUndeliverable : " + 
                 data.Results[i].NotSentDueToUndeliverable + '\n');
      }
     
    }
  }
    catch(ex){
        Write(e.Message);
  }
</script>
                            

Write a WS-Proxy code via SSJS to retrieve subscribers

<script runat="server" language="javascript">
  Platform.Load("core", "1");
  try{
    var prox = new Script.Util.WSProxy();
  var cols = [
  "CreatedDate","ModifiedDate"
  ,"Subscriber.SubscriberKey","Subscriber.Status",
   "Subscriber.UnsubscribedDate","Subscriber.EmailAddress"
  ,"List.ID","List.ListName"
  ];
  prox.setClientId({
    "ID": Platform.Function.AuthenticatedMemberID()
    }
  );
  var filter = {
    Property: "Status",
  SimpleOperator: "equals",
  Value: "Held"
    };
  var data = prox.retrieve("SubscriberList", cols,filter);
  var counter = 1;
  for (var i = 0; i < data.Results.length; i++) {
    Write("Subscriber List  :" + '\n')
      Write('\n')
  Write( "Created Date :" + data.Results[i].CreatedDate + '\n');
  Write( "Modified Date :" + data.Results[i].ModifiedDate + '\n');
  Write( "List Status :" + data.Results[i].Status + '\n');
  Write( "CustomerKey :" + data.Results[i].CustomerKey + '\n');
  Write('\n')
  Write("List Details :"+'\n')
  Write('\n')
  Write("List ID : "+ data.Results[i].List.ID + '\n');
  Write( "Created Date : "+ data.Results[i].List.CreatedDate + '\n');
  Write( "List Name : "+ data.Results[i].List.ListName + '\n');
  Write("TYpe :" + data.Results[i].List.Type + '\n');
  Write("List Classification :"+data.Results[i].List.ListClassification + '\n');
  Write('\n')

  Write("Subscriber Details :"+'\n')
  Write('\n')
  Write( "Subscriber Key :" + data.Results[i].Subscriber.SubscriberKey + '\n');
  Write( "Email Address:" +  data.Results[i].Subscriber.EmailAddress + '\n');
  Write(  "Status:" + data.Results[i].Subscriber.Status + '\n');
  Write( "Email Type Preference:" + data.Results[i].Subscriber.EmailTypePreference + 
        '\n');
  Write('\n')

  Write( "===================================================" + '\n')

  counter++;
    }
   // Write(Stringify(data));
  }
  catch(ex){
    Write(e.Message);
  }
</script>
                            

Write a WS-Proxy code via SSJS to update subscribers to publication list

<script runat="server">
Platform.Load("core", "1.1");
var prox = new Script.Util.WSProxy();
var MemberDE = DataExtension.Init("DE ExtenalKey");
var DERows = MemberDE.Rows.Retrieve();
for (var i = 0; i < DERows.length; i++) { 
try {
var subKey=DERows[i].CampaignId;
var email=DERows[i].Email;
var Id=DERows[i].ListId;
var status=DERows[i].Status;
var sub = { 
			SubscriberKey: subKey,
            EmailAddress: email,
            Lists: [{ ID: Id, Status: status }] 
          }; 
 var options = { SaveOptions: [{ PropertyName: '*', SaveAction: 'UpdateAdd' }] };
 var data = prox.createItem("Subscriber", sub, options);
 Write(data.Results[0].StatusCode + "<br>"); 
 } catch (e) {
 Write("Exception: " + e.message + "<br>");
 Write("Description: " + e.description + "<br>");
 }
 } 
 </script>
                            

Write a WS-Proxy code via SSJS to retrieve publication list ID

<script runat="server">
Platform.Load("core", "1"); 
try { 
		var soapObjects=[ 
        				 "Publication" ,
                         "Account" ,
                         "AccountUser" ,
                         "Authentication" ,
                         "Automation" ,
                         "BounceEvent" ,
                         "BusinessUnit" ,
                         "ClickEvent" ,
                         "ContentArea" ,
                         "DataExtension" ,
                         "DataFolder" ,
                         "Email" ,
                         "Send" ,
                         "SendClassification"
                         ] 
 var cols = [ "Name","ID"];
 var response=RetrieveSoapObject(soapObjects[0],cols);
 Write(Stringify(response));
 } catch (ex) {
 Write(ex.message + '\n');
 Write(ex.description + '\n');
 Write(ex.jintException + '\n'); 
 } 
 
 function RetrieveSoapObject(soapObjectname,cols ) { 
 var api = new Script.Util.WSProxy();
 var response = api.retrieve(soapObjectname,cols);
 return response; 
 } 
 </script>
                            

Write a WS-Proxy code via SSJS to retrieve Triggered Send Summary

<script runat="server">
  Platform.Load("core", "1");
try {
  // Set the name of the SOAP object to "DataExtension".
  var soapObject = "TriggeredSendSummary";

  // Call the function 'DescribeSoapObject' to retrieve the metadata information for the SOAP object.
  var describeResponse = DescribeSoapObject(soapObject);

  // Extract the properties array from the describeResponse.
  var properties = describeResponse.Results[0].Properties;

  // Call the function 'FetchRetrieveableProperties' to get an array of retrieveable property names.
  var cols = FetchRetrieveableProperties(properties);

  // Apply a filter for the SOAP object, where the "TargetUpdateType" property equals "Overwrite".
  var filter = {};

  // Call the function 'RetrieveSoapObject' to retrieve data from the SOAP object using the specified filter and columns.
  var response = RetrieveSoapObject(soapObject, cols, filter);

  // Convert the response object to a string representation and write it to the output.
  Write(Stringify(response.Results));
}
catch (ex) {
  // If an exception occurs during the execution, catch it and write the error messages to the output.
  Write(ex.message + '\n');
  Write(ex.description + '\n');
  Write(ex.jintException + '\n');
}


// Function to describe a SOAP object using WSProxy.
// Parameters:
// - soapObjectname: The name of the SOAP object to describe.

function DescribeSoapObject(soapObjectname) {
  // Create a new instance of WSProxy to interact with the SOAP API.
  var api = new Script.Util.WSProxy();

  // Call the describe method of WSProxy to fetch the metadata information for the SOAP object.
  var response = api.describe(soapObjectname);

  // Return the response, which contains the metadata information for the SOAP object.
  return response;
}

  
// Function to fetch an array of retrieveable property names from SOAP metadata.
// Parameters:
// - soapMetaData: An array of objects containing metadata information for SOAP properties.

function FetchRetrieveableProperties(soapMetaData) {
  // Create an empty array to store the names of retrieveable properties.
  var propertiesName = [];

  // Iterate through each object in the soapMetaData array.
  for (var i in soapMetaData) {
    // Extract the 'Name' property from the current object and store it in the propertiesName array.
    var name = soapMetaData[i].Name;
    var isRetrievable=soapMetaData[i].IsRetrievable
    if(isRetrievable===true)
       propertiesName.push(name);
  }

  // Return the array containing the names of retrieveable properties.
  return propertiesName;
}


// Function to create a filter object for data retrieval or processing.
// Parameters:
// - prop: The property name to filter on.
// - operator: The operator used for filtering (e.g., equals, greater than, less than, etc.).
// - value: The value to compare the property against.

function ApplyFilter(prop, operator, value) {
  // Create and return a filter object with the specified properties.
  return {
    Property: prop,         // The property name on which the filter is applied.
    SimpleOperator: operator, // The operator used for the filter (e.g., 'equals', 'greaterThan', etc.).
    Value: value            // The value to compare the property against.
  };
}


// Function to retrieve data from a SOAP object using WSProxy.
// Parameters:
// - soapObjectname: The name of the SOAP object from which data will be retrieved.
// - cols: An array of column names to retrieve from the SOAP object.
// - filter: A filter to apply when querying the SOAP object (optional).

function RetrieveSoapObject(soapObjectname, cols) {
  // Create a new instance of WSProxy to interact with the SOAP object.
  var api = new Script.Util.WSProxy();

  // Call the retrieve method of WSProxy to fetch data from the SOAP object.
  var response = api.retrieve(soapObjectname, cols);

  // Return the response, which contains the retrieved data from the SOAP object.
  return response;
}

  
</script>
                            

Write a WS-Proxy code via SSJS to retrieve SMS Triggered Send Summary

<script runat="server">
  Platform.Load("core", "1");
try {
  // Set the name of the SOAP object to "DataExtension".
  var soapObject = "SMSTriggeredSend";

  // Call the function 'DescribeSoapObject' to retrieve the metadata information for the SOAP object.
  var describeResponse = DescribeSoapObject(soapObject);

  // Extract the properties array from the describeResponse.
  var properties = describeResponse.Results[0].Properties;

  // Call the function 'FetchRetrieveableProperties' to get an array of retrieveable property names.
  var cols = FetchRetrieveableProperties(properties);

  // Apply a filter for the SOAP object, where the "TargetUpdateType" property equals "Overwrite".
  var filter = {};

  // Call the function 'RetrieveSoapObject' to retrieve data from the SOAP object using the specified filter and columns.
  var response = RetrieveSoapObject(soapObject, cols, filter);

  // Convert the response object to a string representation and write it to the output.
  Write(Stringify(response.Results));
}
catch (ex) {
  // If an exception occurs during the execution, catch it and write the error messages to the output.
  Write(ex.message + '\n');
  Write(ex.description + '\n');
  Write(ex.jintException + '\n');
}


// Function to describe a SOAP object using WSProxy.
// Parameters:
// - soapObjectname: The name of the SOAP object to describe.

function DescribeSoapObject(soapObjectname) {
  // Create a new instance of WSProxy to interact with the SOAP API.
  var api = new Script.Util.WSProxy();

  // Call the describe method of WSProxy to fetch the metadata information for the SOAP object.
  var response = api.describe(soapObjectname);

  // Return the response, which contains the metadata information for the SOAP object.
  return response;
}

  
// Function to fetch an array of retrieveable property names from SOAP metadata.
// Parameters:
// - soapMetaData: An array of objects containing metadata information for SOAP properties.

function FetchRetrieveableProperties(soapMetaData) {
  // Create an empty array to store the names of retrieveable properties.
  var propertiesName = [];

  // Iterate through each object in the soapMetaData array.
  for (var i in soapMetaData) {
    // Extract the 'Name' property from the current object and store it in the propertiesName array.
    var name = soapMetaData[i].Name;
    var isRetrievable=soapMetaData[i].IsRetrievable
    if(isRetrievable===true)
       propertiesName.push(name);
  }

  // Return the array containing the names of retrieveable properties.
  return propertiesName;
}


// Function to create a filter object for data retrieval or processing.
// Parameters:
// - prop: The property name to filter on.
// - operator: The operator used for filtering (e.g., equals, greater than, less than, etc.).
// - value: The value to compare the property against.

function ApplyFilter(prop, operator, value) {
  // Create and return a filter object with the specified properties.
  return {
    Property: prop,         // The property name on which the filter is applied.
    SimpleOperator: operator, // The operator used for the filter (e.g., 'equals', 'greaterThan', etc.).
    Value: value            // The value to compare the property against.
  };
}


// Function to retrieve data from a SOAP object using WSProxy.
// Parameters:
// - soapObjectname: The name of the SOAP object from which data will be retrieved.
// - cols: An array of column names to retrieve from the SOAP object.
// - filter: A filter to apply when querying the SOAP object (optional).

function RetrieveSoapObject(soapObjectname, cols) {
  // Create a new instance of WSProxy to interact with the SOAP object.
  var api = new Script.Util.WSProxy();

  // Call the retrieve method of WSProxy to fetch data from the SOAP object.
  var response = api.retrieve(soapObjectname, cols);

  // Return the response, which contains the retrieved data from the SOAP object.
  return response;
}

  
</script>
                            

Write a WS-Proxy code via SSJS to retrieve Import Definition and Upsert into a data extension

<script runat="server">
  Platform.Load("core", "1");
try {
  // Set the name of the SOAP object to "ImportDefinition".
  var soapObject = "ImportDefinition";

  // Call the function 'DescribeSoapObject' to retrieve the metadata information for the SOAP object.
  var describeResponse = DescribeSoapObject(soapObject);

  // Extract the properties array from the describeResponse.
  var properties = describeResponse.Results[0].Properties;

  // Call the function 'FetchRetrieveableProperties' to get an array of retrieveable property names.
  var cols = FetchRetrieveableProperties(properties);

  // Call the function 'RetrieveSoapObject' to retrieve data from the SOAP object using the specified columns.
  var response = RetrieveSoapObject(soapObject, cols);
  
  var results = upsertDataExtension(response);

  // Convert the response object to a string representation and write it to the output.
  Write(Stringify(results));
}
catch (ex) {
  // If an exception occurs during the execution, catch it and write the error messages to the output.
  Write(ex.message + '\n');
  Write(ex.description + '\n');
  Write(ex.jintException + '\n');
}


// Function to describe a SOAP object using WSProxy.
// Parameters:
// - soapObjectname: The name of the SOAP object to describe.

function DescribeSoapObject(soapObjectname) {
  // Create a new instance of WSProxy to interact with the SOAP API.
  var api = new Script.Util.WSProxy();

  // Call the describe method of WSProxy to fetch the metadata information for the SOAP object.
  var response = api.describe(soapObjectname);

  // Return the response, which contains the metadata information for the SOAP object.
  return response;
}

  
// Function to fetch an array of retrieveable property names from SOAP metadata.
// Parameters:
// - soapMetaData: An array of objects containing metadata information for SOAP properties.

function FetchRetrieveableProperties(soapMetaData) {
  // Create an empty array to store the names of retrieveable properties.
  var propertiesName = [];

  // Iterate through each object in the soapMetaData array.
  for (var i in soapMetaData) {
    // Extract the 'Name' property from the current object and store it in the propertiesName array.
    var name = soapMetaData[i].Name;
    var isRetrievable = soapMetaData[i].IsRetrievable;
    if (isRetrievable === true)
       propertiesName.push(name);
  }

  // Return the array containing the names of retrieveable properties.
  return propertiesName;
}


// Function to create a filter object for data retrieval or processing.
// Parameters:
// - prop: The property name to filter on.
// - operator: The operator used for filtering (e.g., equals, greater than, less than, etc.).
// - value: The value to compare the property against.

function ApplyFilter(prop, operator, value) {
  // Create and return a filter object with the specified properties.
  return {
    Property: prop,         // The property name on which the filter is applied.
    SimpleOperator: operator, // The operator used for the filter (e.g., 'equals', 'greaterThan', etc.).
    Value: value            // The value to compare the property against.
  };
}


// Function to retrieve data from a SOAP object using WSProxy.
// Parameters:
// - soapObjectname: The name of the SOAP object from which data will be retrieved.
// - cols: An array of column names to retrieve from the SOAP object.
// - filter: A filter to apply when querying the SOAP object (optional).

function RetrieveSoapObject(soapObjectname, cols, filter) {
  // Create a new instance of WSProxy to interact with the SOAP object.
  var api = new Script.Util.WSProxy();

  // Call the retrieve method of WSProxy to fetch data from the SOAP object.
  var response = api.retrieve(soapObjectname, cols, filter);

  // Return the response, which contains the retrieved data from the SOAP object.
  return response;
}

  
  /**
 * Upsert data extension with response data.
 * @param {Object} response - The response data containing fields like CustomerKey, CreatedDate, ModifiedDate, Name, Description, and EmailSubject.
 */
function upsertDataExtension(response) {
    // Create a new instance of WSProxy to interact with the SOAP object.
    var api = new Script.Util.WSProxy();
    var res;
    var results = [];

    for (var i = 0; i < response.Results.length; i++) {
        // Build data extension object for each result
        var updateObject = {
            CustomerKey: 'ImportDefinition',
            Properties: [
                { Name: 'CustomerKey', Value: response.Results[i].CustomerKey },
                { Name: 'ObjectID', Value: response.Results[i].ObjectID },
                { Name: 'LocaleCode', Value: response.Results[i].DateFormattingLocale.LocaleCode },
                { Name: 'Name', Value: response.Results[i].Name },
                { Name: 'SubscriberImportType', Value: response.Results[i].SubscriberImportType },
                { Name: 'Description', Value: response.Results[i].Description },
                { Name: 'FileTransferLocationID', Value: response.Results[i].RetrieveFileTransferLocation.ObjectID },
                { Name: 'FileSpec', Value: response.Results[i].FileSpec },
                { Name: 'FieldMappingType', Value: response.Results[i].FieldMappingType },
                { Name: 'DestinationObjectID', Value: response.Results[i].DestinationObject.ObjectID },
                { Name: 'AllowErrors', Value: response.Results[i].AllowErrors },
                { Name: 'UpdateType', Value: response.Results[i].UpdateType }
            ]
        };

        var options = {
            SaveOptions: [{ PropertyName: '*', SaveAction: 'UpdateAdd' }]
        };

        // Update data extension object
        res = api.updateItem('DataExtensionObject', updateObject, options);
        results.push(res);
    }

    // Log the response
    return results;
}
  
</script>

                            

Write a WS-Proxy code via SSJS to retrieve Import Results Summary and Upsert into a data extension

<script runat="server">
  Platform.Load("core", "1");

  try {
    // Set the name of the SOAP object to "ImportResultsSummary".
    var soapObject = "ImportResultsSummary";

    // Call the function 'DescribeSoapObject' to retrieve the metadata information for the SOAP object.
    var describeResponse = DescribeSoapObject(soapObject);

    // Extract the properties array from the describeResponse.
    var properties = describeResponse.Results[0].Properties;

    // Call the function 'FetchRetrieveableProperties' to get an array of retrieveable property names.
    var cols = FetchRetrieveableProperties(properties);

    // Call the function 'RetrieveSoapObject' to retrieve data from the SOAP object using the specified columns.
    var response = RetrieveSoapObject(soapObject, cols);

    // Upsert the retrieved data into the Data Extension.
    var results = upsertDataExtension(response);

    // Convert the response object to a string representation and write it to the output.
    Write(Stringify(results));
  } catch (ex) {
    // If an exception occurs during the execution, catch it and write the error messages to the output.
    Write("Exception: " + ex.message + '\n');
  }

  // Function to describe a SOAP object using WSProxy.
  // Parameters:
  // - soapObjectname: The name of the SOAP object to describe.
  function DescribeSoapObject(soapObjectname) {
    // Create a new instance of WSProxy to interact with the SOAP API.
    var api = new Script.Util.WSProxy();

    // Call the describe method of WSProxy to fetch the metadata information for the SOAP object.
    var response = api.describe(soapObjectname);

    // Return the response, which contains the metadata information for the SOAP object.
    return response;
  }

  // Function to fetch an array of retrieveable property names from SOAP metadata.
  // Parameters:
  // - soapMetaData: An array of objects containing metadata information for SOAP properties.
  function FetchRetrieveableProperties(soapMetaData) {
    // Create an empty array to store the names of retrieveable properties.
    var propertiesName = [];

    // Iterate through each object in the soapMetaData array.
    for (var i in soapMetaData) {
      // Extract the 'Name' property from the current object and store it in the propertiesName array.
      var name = soapMetaData[i].Name;
      var isRetrievable = soapMetaData[i].IsRetrievable;
      if (isRetrievable === true)
         propertiesName.push(name);
    }

    // Return the array containing the names of retrieveable properties.
    return propertiesName;
  }

  // Function to retrieve data from a SOAP object using WSProxy.
  // Parameters:
  // - soapObjectname: The name of the SOAP object from which data will be retrieved.
  // - cols: An array of column names to retrieve from the SOAP object.
  function RetrieveSoapObject(soapObjectname, cols) {
    // Create a new instance of WSProxy to interact with the SOAP object.
    var api = new Script.Util.WSProxy();

    // Call the retrieve method of WSProxy to fetch data from the SOAP object.
    var response = api.retrieve(soapObjectname, cols);

    // Return the response, which contains the retrieved data from the SOAP object.
    return response;
  }

  // Function to upsert data extension with response data.
  // Parameters:
  // - response: The response data containing fields like CustomerKey, CreatedDate, ModifiedDate, Name, Description, and EmailSubject.
  function upsertDataExtension(response) {
    // Create a new instance of WSProxy to interact with the SOAP object.
    var api = new Script.Util.WSProxy();
    var res;
    var results=[];

    for (var i = 0; i < response.Results.length; i++) {
      // Build data extension object for each result
      var updateObject = {
        CustomerKey: 'ImportDefinitionResults',
        Properties: [
          { Name: 'ObjectID', Value: response.Results[i].ObjectID },
          { Name: 'TaskResultID', Value: response.Results[i].TaskResultID },
          { Name: 'ImportStatus', Value: response.Results[i].ImportStatus },
          { Name: 'ImportType', Value: response.Results[i].ImportType },
          { Name: 'TotalRows', Value: response.Results[i].TotalRows },
          { Name: 'NumberRestricted', Value: response.Results[i].NumberRestricted },
          { Name: 'NumberDuplicated', Value: response.Results[i].NumberDuplicated },
          { Name: 'NumberSuccessful', Value: response.Results[i].NumberSuccessful },
          { Name: 'DestinationID', Value: response.Results[i].DestinationID },
          { Name: 'EndDate', Value: response.Results[i].EndDate },
          { Name: 'StartDate', Value: response.Results[i].StartDate },
          { Name: 'ImportDefinitionCustomerKey', Value: response.Results[i].ImportDefinitionCustomerKey },
          { Name: 'NumberErrors', Value: response.Results[i].NumberErrors }
        ]
      };

      var options = {
        SaveOptions: [{ 'PropertyName': '*', SaveAction: 'UpdateAdd' }]
      };

      // Update data extension object
      res = api.updateItem('DataExtensionObject', updateObject, options);
      results.push(res);
    }

    // Log the response
    return results;
  }
</script>


                            

Write a WS-Proxy code via SSJS to create Import definition and run the defintion

<script runat="server">
    // Load necessary libraries
    Platform.Load("core", "1");

    try {
        // Initialize WSProxy API
        var api = new Script.Util.WSProxy();

        // Define variables for Import Definition configuration
        var name = "Demo1"; // Name of the Import Definition
        var deCustomerKey = "SubscribersMaster"; // Data Extension CustomerKey
        var fileSpec = "APIImport%%Year%%%%Month%%%%Day%%.psv"; // File specification
        var fileType = "Other"; //"Tab,CSV" Type of file
        var createResults = CreateImportDefinition(api, name, deCustomerKey, fileSpec, fileType);

        Write(Stringify(createResults));
        
    } catch (ex) {
        // Catch and log any errors that occur
        Write(Stringify(ex));
    }

    // Function to create an Import Definition
    function CreateImportDefinition(api, name, deCustomerKey, fileSpec, fileType) {
        try {
            // Create an Import Definition object
            var config = {
                Name: name,
                CustomerKey: name, // CustomerKey is usually unique identifier, here set to the same as Name
                Description: name, // Description set to the same as Name
                AllowErrors: true,
                DestinationObject: {
                    CustomerKey: deCustomerKey,
                    IDSpecified: true
                },
                Notification: {
                    ResponseType: "email",
                    ResponseAddress: "b2.shashi@gmail.com" // Email address for notification
                },
                RetrieveFileTransferLocation: {
                    CustomerKey: "ExactTarget Enhanced FTP" // File transfer location
                },
                // Update type for import 
                UpdateType: "AddAndUpdate", //Overwrite,AddAndDoNotUpdate,AddAndUpdate
                UpdateTypeSpecified: true,
                // Field mapping type
                FieldMappingType: "InferFromColumnHeadings", //MapByOrdinal,ManualMap
                FieldMappingTypeSpecified: true,
                FieldMaps: CreateFieldMap(), // Field mappings
                FileSpec: fileSpec, // File specification
                FileType: fileType,
                FileTypeSpecified: true,
                StandardQuotedStrings: true,
                Delimiter: "|",//","
                HeaderLines: 1
            };

            // Create the Import Definition
            var result = api.createItem("ImportDefinition", config);
            return result;
        } catch (ex) {
            throw ex;
        }
    }

    // Function to create field mappings
    function CreateFieldMap() {
        return [
            {
                DestinationName: "SubscriberKey", // Destination field name
                Item: "1" // Source column index
            },
            {
                DestinationName: "Email", // Destination field name
                Item: "2" // Source column index
            }
        ];
    }

     // Function to run the Import Definition activity
     function RunQueryImportActivity(definitionName) {
        // Initialize WSProxy API
        var api = new Script.Util.WSProxy();
        
        // Retrieve ObjectID of the Import Definition for the given name
        var request = api.retrieve("ImportDefinition", ["ObjectID"], {
            Property: "Name",
            SimpleOperator: "equals",
            Value: definitionName
        });
        
        // Extract ObjectID from the response
        var objectId = request.Results[0].ObjectID;
        
        // Properties for running the Import Definition activity
        var props = {
            "ObjectID": objectId 
        };
        
        // Run the Import Definition activity
        var result = api.performItem("ImportDefinition", props, "Start", {});
        return result;
    }
</script>


                            

Write a WS-Proxy code via SSJS to retrieve Shared Data extension from child BU

<script runat="server">
  Platform.Load("core", "1");
try {
  // Set the name of the SOAP object to "DataExtension".
  var soapObject = "DataExtension";

  // Call the function 'DescribeSoapObject' to retrieve the metadata information for the SOAP object.
  var describeResponse = DescribeSoapObject(soapObject);

  // Extract the properties array from the describeResponse.
  var properties = describeResponse.Results[0].Properties;

  // Call the function 'FetchRetrieveableProperties' to get an array of retrieveable property names.
  var cols = FetchRetrieveableProperties(properties);

  // Apply a filter for the SOAP object, where the "IsSendable" property equals "true".
  var filter = ApplyFilter("Customerkey", "equals", "1sgHr000000TNCmIAO_85RHr000000PAvqMAG_I");

  // Call the function 'RetrieveSoapObject' to retrieve data from the SOAP object using the specified filter and columns.
  var response = RetrieveSoapObject(soapObject, cols, filter);

  // Convert the response object to a string representation and write it to the output.
  Write(Stringify(response.Results));
}
catch (ex) {
  // If an exception occurs during the execution, catch it and write the error messages to the output.
  Write(ex.message + '\n');
  Write(ex.description + '\n');
  Write(ex.jintException + '\n');
}


// Function to describe a SOAP object using WSProxy.
// Parameters:
// - soapObjectname: The name of the SOAP object to describe.

function DescribeSoapObject(soapObjectname) {
  // Create a new instance of WSProxy to interact with the SOAP API.
  var api = new Script.Util.WSProxy();

  // Call the describe method of WSProxy to fetch the metadata information for the SOAP object.
  var response = api.describe(soapObjectname);

  // Return the response, which contains the metadata information for the SOAP object.
  return response;
}

  
// Function to fetch an array of retrieveable property names from SOAP metadata.
// Parameters:
// - soapMetaData: An array of objects containing metadata information for SOAP properties.

function FetchRetrieveableProperties(soapMetaData) {
  // Create an empty array to store the names of retrieveable properties.
  var propertiesName = [];
 

  // Iterate through each object in the soapMetaData array.
  for (var i in soapMetaData) {
    // Extract the 'Name' property from the current object and store it in the propertiesName array.
    var name = soapMetaData[i].Name;
    var isRetrievable=soapMetaData[i].IsRetrievable
    if(isRetrievable===true)
       propertiesName.push(name);
  }

  // Return the array containing the names of retrieveable properties.
  return propertiesName;
}


// Function to create a filter object for data retrieval or processing.
// Parameters:
// - prop: The property name to filter on.
// - operator: The operator used for filtering (e.g., equals, greater than, less than, etc.).
// - value: The value to compare the property against.

function ApplyFilter(prop, operator, value) {
  // Create and return a filter object with the specified properties.
  return {
    Property: prop,         // The property name on which the filter is applied.
    SimpleOperator: operator, // The operator used for the filter (e.g., 'equals', 'greaterThan', etc.).
    Value: value            // The value to compare the property against.
  };
}


// Function to retrieve data from a SOAP object using WSProxy.
// Parameters:
// - soapObjectname: The name of the SOAP object from which data will be retrieved.
// - cols: An array of column names to retrieve from the SOAP object.
// - filter: A filter to apply when querying the SOAP object (optional).

function RetrieveSoapObject(soapObjectname, cols, filter) {
  // Create a new instance of WSProxy to interact with the SOAP object.
  var api = new Script.Util.WSProxy();
  var queryAllAccounts = true;

  // Call the retrieve method of WSProxy to fetch data from the SOAP object.
  var response = api.retrieve(soapObjectname, cols, filter,queryAllAccounts);

  // Return the response, which contains the retrieved data from the SOAP object.
  return response;
}

  
</script>
                         

                            

Write a WS-Proxy code via SSJS to retrieve Account Users from child BU

<script runat="server">
  Platform.Load("core", "1");
try {
  // Set the name of the SOAP object to "DataExtension".
  var soapObject = "AccountUser";

  // Call the function 'DescribeSoapObject' to retrieve the metadata information for the SOAP object.
  var describeResponse = DescribeSoapObject(soapObject);

  // Extract the properties array from the describeResponse.
  var properties = describeResponse.Results[0].Properties;

  // Call the function 'FetchRetrieveableProperties' to get an array of retrieveable property names.
  var cols = FetchRetrieveableProperties(properties);


  // Call the function 'RetrieveSoapObject' to retrieve data from the SOAP object using the specified filter and columns.
  var response = RetrieveSoapObject(soapObject, cols);

  // Convert the response object to a string representation and write it to the output.
  Write(Stringify(response));
}
catch (ex) {
  // If an exception occurs during the execution, catch it and write the error messages to the output.
  Write(ex.message + '\n');
  Write(ex.description + '\n');
  Write(ex.jintException + '\n');
}


// Function to describe a SOAP object using WSProxy.
// Parameters:
// - soapObjectname: The name of the SOAP object to describe.

function DescribeSoapObject(soapObjectname) {
  // Create a new instance of WSProxy to interact with the SOAP API.
  var api = new Script.Util.WSProxy();

  // Call the describe method of WSProxy to fetch the metadata information for the SOAP object.
  var response = api.describe(soapObjectname);

  // Return the response, which contains the metadata information for the SOAP object.
  return response;
}

  
// Function to fetch an array of retrieveable property names from SOAP metadata.
// Parameters:
// - soapMetaData: An array of objects containing metadata information for SOAP properties.

function FetchRetrieveableProperties(soapMetaData) {
  // Create an empty array to store the names of retrieveable properties.
  var propertiesName = [];

  // Iterate through each object in the soapMetaData array.
  for (var i in soapMetaData) {
    // Extract the 'Name' property from the current object and store it in the propertiesName array.
    var name = soapMetaData[i].Name;
    var isRetrievable=soapMetaData[i].IsRetrievable
    if(isRetrievable===true)
       propertiesName.push(name);
  }

  // Return the array containing the names of retrieveable properties.
  return propertiesName;
}


// Function to create a filter object for data retrieval or processing.
// Parameters:
// - prop: The property name to filter on.
// - operator: The operator used for filtering (e.g., equals, greater than, less than, etc.).
// - value: The value to compare the property against.

function ApplyFilter(prop, operator, value) {
  // Create and return a filter object with the specified properties.
  return {
    Property: prop,         // The property name on which the filter is applied.
    SimpleOperator: operator, // The operator used for the filter (e.g., 'equals', 'greaterThan', etc.).
    Value: value            // The value to compare the property against.
  };
}


// Function to retrieve data from a SOAP object using WSProxy.
// Parameters:
// - soapObjectname: The name of the SOAP object from which data will be retrieved.
// - cols: An array of column names to retrieve from the SOAP object.
// - filter: A filter to apply when querying the SOAP object (optional).

function RetrieveSoapObject(soapObjectname, cols, filter) {
  // Create a new instance of WSProxy to interact with the SOAP object.
  var api = new Script.Util.WSProxy();
  var queryAllAccounts = true;

  // Call the retrieve method of WSProxy to fetch data from the SOAP object.
  var response = api.retrieve(soapObjectname, cols, null,queryAllAccounts);

  // Return the response, which contains the retrieved data from the SOAP object.
  return response;
}

  
</script>
                 

                            

Write a WS-Proxy code via SSJS to retrieve Child Publication List from Parent BU

<script runat="server">
  Platform.Load("core", "1");
try {
  // Set the name of the SOAP object to "Publication".
  var soapObject = "Publication";

  // Call the function 'DescribeSoapObject' to retrieve the metadata information for the SOAP object.
  var describeResponse = DescribeSoapObject(soapObject);

  // Extract the properties array from the describeResponse.
  var properties = describeResponse.Results[0].Properties;

  // Call the function 'FetchRetrieveableProperties' to get an array of retrieveable property names.
  var cols = FetchRetrieveableProperties(properties);

  // Apply a filter for the SOAP object, where the "ID" property equals "12345".
  //var filter = ApplyFilter("ID", "equals", "12345");

  // Call the function 'RetrieveSoapObject' to retrieve data from the SOAP object using the specified filter and columns.
  //var response = RetrieveSoapObject(soapObject, cols, filter);
  var response = RetrieveSoapObject(soapObject, cols);

  // Convert the response object to a string representation and write it to the output.
  Write(Stringify(response));
}
catch (ex) {
  // If an exception occurs during the execution, catch it and write the error messages to the output.
  Write(ex.message + '\n');
  Write(ex.description + '\n');
  Write(ex.jintException + '\n');
}


// Function to describe a SOAP object using WSProxy.
// Parameters:
// - soapObjectname: The name of the SOAP object to describe.

function DescribeSoapObject(soapObjectname) {
  // Create a new instance of WSProxy to interact with the SOAP API.
  var api = new Script.Util.WSProxy();

  // Call the describe method of WSProxy to fetch the metadata information for the SOAP object.
  var response = api.describe(soapObjectname);

  // Return the response, which contains the metadata information for the SOAP object.
  return response;
}

  
// Function to fetch an array of retrieveable property names from SOAP metadata.
// Parameters:
// - soapMetaData: An array of objects containing metadata information for SOAP properties.

function FetchRetrieveableProperties(soapMetaData) {
  // Create an empty array to store the names of retrieveable properties.
  var propertiesName = [];

  // Iterate through each object in the soapMetaData array.
  for (var i in soapMetaData) {
    // Extract the 'Name' property from the current object and store it in the propertiesName array.
    var name = soapMetaData[i].Name;
    var isRetrievable=soapMetaData[i].IsRetrievable
    if(isRetrievable===true)
       propertiesName.push(name);
  }

  // Return the array containing the names of retrieveable properties.
  return propertiesName;
}


// Function to create a filter object for data retrieval or processing.
// Parameters:
// - prop: The property name to filter on.
// - operator: The operator used for filtering (e.g., equals, greater than, less than, etc.).
// - value: The value to compare the property against.

function ApplyFilter(prop, operator, value) {
  // Create and return a filter object with the specified properties.
  return {
    Property: prop,         // The property name on which the filter is applied.
    SimpleOperator: operator, // The operator used for the filter (e.g., 'equals', 'greaterThan', etc.).
    Value: value            // The value to compare the property against.
  };
}


// Function to retrieve data from a SOAP object using WSProxy.
// Parameters:
// - soapObjectname: The name of the SOAP object from which data will be retrieved.
// - cols: An array of column names to retrieve from the SOAP object.
// - filter: A filter to apply when querying the SOAP object (optional).

function RetrieveSoapObject(soapObjectname, cols) {
  // Create a new instance of WSProxy to interact with the SOAP object.
  var api = new Script.Util.WSProxy();
  var queryAllAccounts = true;
  // Call the retrieve method of WSProxy to fetch data from the SOAP object.
  var response = api.retrieve(soapObjectname, cols, null,queryAllAccounts);

  // Return the response, which contains the retrieved data from the SOAP object.
  return response;
}

  
</script>
                   
                 

                            

Write a WS-Proxy code via SSJS to retrieve Subscribers based on Profile Attributes

<script runat="server">
  Platform.Load("core", "1");
  try {
    var soapObject = "Subscriber";
    var describeResponse = DescribeSoapObject(soapObject);
    var properties = describeResponse.Results[0].Properties;
    var cols = FetchRetrieveableProperties(properties);
    
    // Fetch all Subscribers (without filter)
    var response = RetrieveSoapObject(soapObject, cols);
    
    // Filter the results based on the Attributes array
    var filteredResults = FilterResponseByAttribute(response, "LOB", "Shashi"); // Adjust attribute name and value as needed
    
    // Convert the filtered results to a string representation and write it to the output.
    Write(Stringify(filteredResults));
  }
  catch (ex) {
    Write(ex.message + '\n');
    Write(ex.description + '\n');
    Write(ex.jintException + '\n');
  }

  // Function to describe a SOAP object using WSProxy.
  function DescribeSoapObject(soapObjectname) {
    var api = new Script.Util.WSProxy();
    var response = api.describe(soapObjectname);
    return response;
  }

  // Function to fetch an array of retrievable property names from SOAP metadata.
  function FetchRetrieveableProperties(soapMetaData) {
    var propertiesName = [];
    for (var i in soapMetaData) {
      var name = soapMetaData[i].Name;
      var isRetrievable = soapMetaData[i].IsRetrievable;
      if (isRetrievable === true) propertiesName.push(name);
    }
    return propertiesName;
  }

  // Function to retrieve data from a SOAP object using WSProxy.
  function RetrieveSoapObject(soapObjectname, cols) {
    var api = new Script.Util.WSProxy();
    var response = api.retrieve(soapObjectname, cols); // No filter applied here
    return response;
  }

  // Function to filter the response based on attribute name and value.
  function FilterResponseByAttribute(response, attrName, attrValue) {
    var filteredResults = [];
    
    if (response && response.Results) {
      for (var i in response.Results) {
        var attributes = response.Results[i].Attributes;
        // Check if the specific attribute exists with the desired value
        for (var j in attributes) {
          if (attributes[j].Name === attrName && attributes[j].Value === attrValue) {
            filteredResults.push(response.Results[i]); // Add subscriber to filtered results
            break; // Stop checking further attributes for this subscriber
          }
        }
      }
    }
    
    return filteredResults; // Return the filtered results
  }
</script>

                 

                            

Write a WS-Proxy code via SSJS to retrieve Subscribers based on Business Unit

<script runat="server">
  Platform.Load("core", "1");
try {
  // Set the name of the SOAP object to "Publication".
  var soapObject = "Subscriber";

  // Call the function 'DescribeSoapObject' to retrieve the metadata information for the SOAP object.
  var describeResponse = DescribeSoapObject(soapObject);

  // Extract the properties array from the describeResponse.
  var properties = describeResponse.Results[0].Properties;

  // Call the function 'FetchRetrieveableProperties' to get an array of retrieveable property names.
  var cols = FetchRetrieveableProperties(properties);

  // Apply a filter for the SOAP object, where the "MID" property equals "12345".
  var filter = ApplyFilter("Client.ID", "equals", "12345");

  // Call the function 'RetrieveSoapObject' to retrieve data from the SOAP object using the specified filter and columns.
  //var response = RetrieveSoapObject(soapObject, cols, filter);
  var response = RetrieveSoapObject(soapObject, cols);

  // Convert the response object to a string representation and write it to the output.
  Write(Stringify(response));
}
catch (ex) {
  // If an exception occurs during the execution, catch it and write the error messages to the output.
  Write(ex.message + '\n');
  Write(ex.description + '\n');
  Write(ex.jintException + '\n');
}


// Function to describe a SOAP object using WSProxy.
// Parameters:
// - soapObjectname: The name of the SOAP object to describe.

function DescribeSoapObject(soapObjectname) {
  // Create a new instance of WSProxy to interact with the SOAP API.
  var api = new Script.Util.WSProxy();

  // Call the describe method of WSProxy to fetch the metadata information for the SOAP object.
  var response = api.describe(soapObjectname);

  // Return the response, which contains the metadata information for the SOAP object.
  return response;
}

  
// Function to fetch an array of retrieveable property names from SOAP metadata.
// Parameters:
// - soapMetaData: An array of objects containing metadata information for SOAP properties.

function FetchRetrieveableProperties(soapMetaData) {
  // Create an empty array to store the names of retrieveable properties.
  var propertiesName = [];

  // Iterate through each object in the soapMetaData array.
  for (var i in soapMetaData) {
    // Extract the 'Name' property from the current object and store it in the propertiesName array.
    var name = soapMetaData[i].Name;
    var isRetrievable=soapMetaData[i].IsRetrievable
    if(isRetrievable===true)
       propertiesName.push(name);
  }

  // Return the array containing the names of retrieveable properties.
  return propertiesName;
}


// Function to create a filter object for data retrieval or processing.
// Parameters:
// - prop: The property name to filter on.
// - operator: The operator used for filtering (e.g., equals, greater than, less than, etc.).
// - value: The value to compare the property against.

function ApplyFilter(prop, operator, value) {
  // Create and return a filter object with the specified properties.
  return {
    Property: prop,         // The property name on which the filter is applied.
    SimpleOperator: operator, // The operator used for the filter (e.g., 'equals', 'greaterThan', etc.).
    Value: value            // The value to compare the property against.
  };
}


// Function to retrieve data from a SOAP object using WSProxy.
// Parameters:
// - soapObjectname: The name of the SOAP object from which data will be retrieved.
// - cols: An array of column names to retrieve from the SOAP object.
// - filter: A filter to apply when querying the SOAP object (optional).

function RetrieveSoapObject(soapObjectname, cols,filter) {
  // Create a new instance of WSProxy to interact with the SOAP object.
  var api = new Script.Util.WSProxy();
  var queryAllAccounts = true;
  // Call the retrieve method of WSProxy to fetch data from the SOAP object.
  var response = api.retrieve(soapObjectname, cols, filter);

  // Return the response, which contains the retrieved data from the SOAP object.
  return response;
}

  
</script>
                   
                            



Comments


Knowledge Article

Most Viewed

CLOUD PAGE ENABLEMENT - PART 1

EMAIL NOT SENT IN JOURNEY BUILDER

CONSIDERATIONS FOR JOURNEY BUILDER

Journey Builder REST API Documentation

Preference Center Demystified

Popular Posts

CLOUD PAGE ENABLEMENT - PART 1

EMAIL NOT SENT IN JOURNEY BUILDER

CONSIDERATIONS FOR JOURNEY BUILDER

Journey Builder REST API Documentation

Preference Center Demystified

SEND LOG EANBLEMENT

Share with Friends

Disclaimer:

The information provided on this technical blog is for general informational purposes only. As a SFMC (Salesforce Marketing Cloud) Technical Architect, I strive to offer accurate and up-to-date content related to SFMC and its associated technologies. However, please note that technology is constantly evolving, and the information provided may become outdated or inaccurate over time.

The content published on this blog represents my personal views and experiences as a SFMC Technical Architect and does not necessarily reflect the official views or opinions of any organization or employer I may be affiliated with.

While I make every effort to ensure the accuracy and reliability of the information presented, I cannot guarantee its completeness, suitability, or applicability to your specific circumstances. Therefore, it is essential to verify any information provided and make your own independent assessments or seek professional advice if needed.

Furthermore, any actions taken based on the information provided on this blog are at your own risk. I shall not be held liable for any damages, losses, or inconveniences arising from the use of the information presented here.

Please keep in mind that SFMC and its associated technologies are complex and require technical expertise for proper implementation and management. It is recommended to consult with qualified professionals or official SFMC documentation for comprehensive guidance.

Finally, please note that any product or company names mentioned on this blog are trademarks or registered trademarks of their respective owners. The mention of these trademarks or registered trademarks does not imply any endorsement or affiliation with the blog.

By accessing and using this blog, you agree to the terms of this disclaimer. If you do not agree with any part of this disclaimer, please refrain from using this blog.