I'm trying to perform a SSJS HTTP GET request to an endpoint that uses "OData", however the call fails (Cloud Page doesn't load). The SSJS GET function in question (seen below) is the only code on the page, there are no other factors.

I need to use the SSJS GET Request for my solution as the endpoint requires the "Auth Bearer Token" Headers; and headers are not able to be passed in AMPScript's GET Request.

Has anyone got a GET or POST request to an OData endpoint working in SSJS?

Sample Code and Documentation:
You can read more about the OData type here.
The documentation on the above link provides an example endpoint. You can call that endpoint in AMPScript as follows:

SET @get = HTTPGet('https://services.odata.org/v4/TripPinServiceRW/People',false,0,@CallStatus)


{"@odata.context":"http://services.odata.org/V4/(S(c4psssbydvwflieflsouvwqs))/TripPinServiceRW/$metadata#People","@odata.nextLink":"https://services.odata.org/V4/(S(c4psssbydvwflieflsouvwqs))/TripPinServiceRW/People?%24skiptoken=8.... etc

AMPScript GET Documentation

The following SSJS code is what is failing on my Cloud Page; despite being a function replication of the AMPScript code above:

<script runat="server">
var responseContent = HTTP.Get('https://services.odata.org/TripPinRESTierService/People');
catch(error) {
Write('Message: '+ error);

SSJS Get Reference Documentation


There's not a lot wrong with your code. If you change this line:

Platform.Load("Core", "1.2");

to this:

Platform.Load("Core", "1");

You'll get the result you're looking for and then you can Platform.Function.ParseJSON(responseContent.Content) to do stuff with your oData records.

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.