6

I've got a email which does a HTTP Get call using SSJS Platform.Function.HTTPGet, results return JSON and I can parse it successfully. Would the calls get cached or would a Get call happen per subscriber? I need it to be cached.

I then came across this Script.Util.HttpGet which should cache the get calls as per docs, however I can't use the parse JSON function as it results in an error.

Unable to retrieve security descriptor for this frame. Line: 7 Char: 1 var json = Platform.Function.ParseJSON(response.content)

Heres a simplified code snippet

 var req =  new Script.Util.HttpGet("https://api.myjson.com/bins/o9qvd");
 var response = req.send();
 var json = Platform.Function.ParseJSON(response.content);

Any recommendations/suggestions, it seems like the get call is successful and I can print the results, but ParseJSON causes the issue

2
  • Can you provide a sample of what is returned? Perhaps the issue is inside the format or structure of your returned JSON or JSON string. Commented Aug 13, 2019 at 17:42
  • 3
    Platform.Response.Write(typeof response.content) returns clr (instead of object), so maybe there's something funky going on behind the scenes with Script.Util.HttpGet.
    – Mark G
    Commented Aug 13, 2019 at 17:51

1 Answer 1

5

It looks like you may need to convert response.content to a String first (initially it's clr; see my comment to your question, above):

var json = Platform.Function.ParseJSON(String(response.content));
Platform.Response.Write(json.name); // mkyong.com
5
  • I would use either HTTPGET (developer.salesforce.com/docs/…) or HTTP.GET from Core (developer.salesforce.com/docs/…) instead of the Util Get. I verifed both of these return the object from your endpoint as a string. Commented Aug 14, 2019 at 13:02
  • 1
    @Gortonington Can these cache content for use in mail sends the way Script.Util.HttpGet does? I think caching content was one of the asker's requirements. I remember a Before;HTTPGet from back in the day, but I haven't seen it used in a Content Builder.
    – Mark G
    Commented Aug 14, 2019 at 13:08
  • 1
    It does not, but do note that if you are using in an email, in a comparison of the processing speeds, I have found that the fastest method is 1 - any GET from AMPscript (can then parse out via GTL) 2 - HTTPGET then HTTP.GET from SSJS and then 3 - any of the script.util (I believe these utilize a proxy server similar to WSProxy, but in this case it is less efficient as the calls need to take at least 4 steps (server to proxy to target to proxy) instead of 2 with the others (server to target). Feel free to do your own comparison, might be different for you. Commented Aug 14, 2019 at 13:15
  • 1
    Also might make more sense to have the GET run via script activity and inserted into either your sendable or a relational DE (referenced with a lookup in email) prior to the send (via an automation) or at scheduled intervals rather than include SSJS inside the email. SSJS in email is not recommended at all. Commented Aug 14, 2019 at 13:20
  • The better way to go is the script activity to retrieve content before send and use GTL. I was initially using GTL but the actual JSON object is a lot more complex than the one I have given as a example here. It involves several levels of nesting, and from what I recall I ran into a few issues when trying to use data objects within different blocks of the email so resulted to SSJS instead. Thanks all for your help!
    – Noor Alam
    Commented Aug 14, 2019 at 14:10

You must log in to answer this question.

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