0

I'm trying to get the last modification date of a template that lives under content builder in salesforce marketing cloud. Is it possible to get it using SSJS or QUERY at all?

UPDATE: Preferable to get it running directly on SFMC and record modification date into a DE

1
  • 1
    ssjs if you use rest api
    – EazyE
    Commented Sep 23, 2021 at 1:47

1 Answer 1

1

You would need to use SSJS to use the REST API. Something like the below would get you there:

//Sample of Str to be passed to do simple query on CB
var clientId = '12345-abcdef';
var clientSecret = '12345-abcdef';
var subDomain = 'w3443234-324dwewwer';
var mid = 123456
var queryStr = '?$filter=name eq {{assetName}}'

var authToken = generateToken(clientId,clientSecret,subDomain,mid)

var asset = getCBAsset(subDomain,queryStr,authToken)

var modifiedDate = asset.items[0].modifiedDate;

function getCBAsset(subDomain,queryStr,authToken) {
  var url = 'https://' + subDomain + '.rest.marketingcloudapis.com/asset/v1/content/assets'
  var contentType = 'application/json'
  var result;
  try {
      result = HTTP.Get(deUrl, ["Authorization"], [authToken]);
  } catch(e) {
      result = e;
  }
  return result;
}

function generateToken(clientId,clientSecret,subDomain,mid) {
  var authJSON = {
  "grant_type": "client_credentials",
  "client_id": clientId,
  "client_secret": clientSecret,
  "account_id": mid
  }

  var authUrl = 'https://' + subDomain + '.auth.marketingcloudapis.com/v2/token';
  var contentType = 'application/json';
  var authPayload = Platform.Function.Stringify(authJSON);

  var accessTokenResult = HTTP.Post(authUrl, contentType, authPayload);
  var response = accessTokenResult["Response"][0];

  var accessToken = Platform.Function.ParseJSON(response).access_token;

  return accessToken;
}

I haven't explicitly run the above, but it should get you where you need to be.

4
  • Thanks! I will give it a try.
    – Joseph
    Commented Sep 23, 2021 at 14:49
  • What if I want to run it directly on marketing cloud and record results into a DE?
    – Joseph
    Commented Sep 23, 2021 at 14:52
  • This would be directly in SFMC. You would put it in a script activity. You then take that modifiedDate variable and use the SSJS UpsertData or something to push it into a DE. Commented Sep 23, 2021 at 19:19
  • Thank you! I will give it a try
    – Joseph
    Commented Sep 24, 2021 at 14:51

You must log in to answer this question.

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