0

I'm successfully getting a result from an HTTP.Post call.

My reply comes in a form of a JSON and looks something like this:

{
"Result": {
    "Message": "",
    "MessageDetails": "",
    "Status": 1
},
"SessionGuid": "*********"
}

I'm trying to save the content of the SessionGuid into a data extension.

I have tried multiple things but nothing worked:

 var result = HTTP.Post(url, contentType, payload);
   var accessToken = Platform.Function.ParseJSON(result);
  var SessionGuid = accessToken.SessionGuid;
  write(SessionGuid);
 // var oResults = eval("(" + result[0] + ")");
 //  var sessionid = Results["SessionGuid"];
 //  var obj = Platform.Function.ParseJSON(result);
 // var  sessionid = result.SessionGuid;
 // var obj = Platform.Function.ParseJSON(results);
 // write(sessionid);
 //var oresults = Stringify(result);
 //   Write(oresults);
 // var resultss = results["StatusCode"];
 // var sessionid = results.StatusCode;
 // Platform.Function.InsertDE("broker",["Response"],[sessionid]);

I left the things i tried in here so you can see. Best thing I could get was to get the whole JSON reply in the DE, by Stringify-ing the result.

Thanks a lot, Andrei

3
  • Are you receiving an error with any of these? Null values? etc. please provide more details Nov 19 '18 at 18:38
  • There are 3 types of replies: 1. I get a server 500 error. 2. I get null values. 3. I get the whole JSON payload in the de. I just need the value of the SessionGuid either in the DE or just to be written on screen at the moment. Nov 19 '18 at 19:41
  • 1
    Have you tried result[0].SessionGuid? I have found declaring the object number seems to be required for SFMC JSON returns - even when there is only 1 level. Nov 19 '18 at 20:08
0

This is what did it for me:

var result = HTTP.Post(url, contentType, payload);
var tokenResponse = Platform.Function.ParseJSON(result.Response[0]);
  var accessToken = tokenResponse.SessionGuid;
    Write(accessToken);
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.