Can someone provide example code for the function Script.Util.HttpResponse or point to a better resource than these help docs?
As a note, Script.Util.HttpResponse is not a user function, it is instead the Response Object from the other Script.Util calls.
For details to correctly parse information from it, I would look at my article on Script.Util.HttpRequest about how to handle the Response from the call (Parsing the Results). This discusses how to grab information from the returned object of an HttpRequest call which is, in actuality, the Script.Util.HttpResponse object as documented in the official docs.
As shown in the documents, the following parameters are available from the object:
You would use these like below:
//assuming var res is the response object from an HttpRequest call var content = res.content; var contentType = res.contentType; var encoding = res.encoding; var headers = res.headers["myHeaderName"]; var status = res.returnStatus var code = res.statusCode
A couple notes though,
res.content is returned as a CLR object, which is not really compatible with SFMC SSJS, so you will need to convert it to a string and then use ParseJSON to turn it into a recognizable object/array to output.
var resStr = String(res.content); var resJSON = Platform.Function.ParseJSON(resStr);
NOTE: If you use Stringify instead, this will not work. You need to change the data type of the object to String or it will not output correctly.From the String version of the JSON you can then parse that into a JSON that you can interact with.
NOTE ON HEADERS:
EDIT 2020-11-09 - Based on info grabbed in this thread if you are getting errors about
"Use of Common Language Runtime (CLR) is not allowed" when working with the headers, you will need to talk to support to turn on an associated Business Rule to allow this.
All this being said, there may be some other quirks or options on this object that I am unaware of as I have not done too extensive research into this. Please feel free to explore and add any comments here if you find anything cool.
Answered by Gortonington on December 27, 2020
13 Asked on January 6, 2022 by vivek-m-chawla
3 Asked on January 6, 2022 by yossi-cadaner
1 Asked on January 6, 2022 by user6366199
0 Asked on January 6, 2022
1 Asked on January 6, 2022 by bergin-panimayam
1 Asked on January 6, 2022 by anthony-williams
3 Asked on January 4, 2022 by brian-miller
1 Asked on January 4, 2022
0 Asked on January 4, 2022 by jason-clark
1 Asked on January 4, 2022 by user85715
0 Asked on January 4, 2022 by tyler-dahle
1 Asked on January 2, 2022 by shivam-shukla
2 Asked on January 2, 2022 by darkskull
1 Asked on January 2, 2022 by alef-ribeiro
2 Asked on January 2, 2022 by snehal
1 Asked on January 2, 2022 by evazi
Get help from others!