I am using this function to check in SSJS if my email exists using the customer key.


  <script runat="server">
    Platform.Load("Core", "1.1.1");

    try {

      var emailKey = 'df_test_email';
      var results = Email.Retrieve({Property:"CustomerKey",SimpleOperator:"equals",Value:emailKey});
      if (results.length < 1) {
          Write("###Email Does Not Exist<br>");

Problem is the results always return zero, even though I know there is an email with the customer key set to df_test_email.

enter image description here

  • 1
    I need to test, but this may not work for Content Builder emails. I'll test shortly and let you know
    – EazyE
    Jun 12, 2019 at 15:35

2 Answers 2


Why don't you use the REST API for this?

<script runat = "server" >
Platform.Load("Core", "1");
var url = 'https://auth.exacttargetapis.com/v1/requestToken';
var contentType = 'application/json';
var request = {
  "clientId": "YOUR CLIENT ID",
  "clientSecret": "YOUR SECRET"
var payload = Platform.Function.Stringify(request);
var result = HTTP.Post(url, contentType, payload);
var aRes = Platform.Function.ParseJSON(result.Response.toString());
var auth = aRes.accessToken;
var url = 'https://www.exacttargetapis.com/asset/v1/content/assets/query';
var contentType = 'application/json';

var request = {
  "query": {
    "leftOperand": {
      "property": "assetType.id",
      "simpleOperator": "equals",
      "valueType": "int",
      "value": 208 //HTMLEmail type
    "logicalOperator": "AND",
    "rightOperand": {
      "property": "name",
      "simpleOperator": "equals",
      "value": "df_test_email"
var payload = Platform.Function.Stringify(request);
var headerNames = ["Authorization"];
var headerValues = ["Bearer " + auth];
var result = HTTP.Post(url, contentType, payload, headerNames, headerValues);
var res = result.Response.toString();
  • I am building this piece of code in SSJS, if there is already a built in SSJS function I'd prefer to use this than resort to using the API within SSJS. Trying to figure out if theres something wrong with the syntax or I'm not doing something quite right. Jun 12, 2019 at 16:14
  • 3
    To my knowledge there is not a built in function like that which will retrieve a content builder asset. You have to use the REST API. Updated my answer to include the full snippet. Jun 12, 2019 at 16:22
  • Just realised I've been trying to recreate the wheel when you've already provided the answer to getting the ID via API here. The same issue still occurs here "System.Collections.Generic.Dictionary`2[System.String,System.Object]". Jun 17, 2019 at 16:33
  • 1
    FYI there is a much smaller resource you can use if you append the ID after /assets/ instead of query. 132KB vs 4.4MB Jun 17, 2019 at 17:02
  • Despite using a filter condition it looks like its just returning all the assets, hence the large payload. (4.3MB) Jun 17, 2019 at 17:03

This may be that you want:

function getemailname(pEID)
          var myEmail = Email.Init("myEmail");
          myEmail =  Email.Retrieve({Property:"ID",SimpleOperator:"equals",Value:pEID});

          for (var i = 0; i < myEmail.length; i++)
              return (myEmail[i].Name);


The reference is from https://developer.salesforce.com/docs/atlas.en-us.mc-programmatic-content.meta/mc-programmatic-content/ssjs_retrieveExternalKey.htm?search_text=Email.Retrieve

  • This does not retrieve content builder assets. Jun 17, 2019 at 16:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .