1

I am trying to return an array of Event objects using SSJS HTTP GET with an authorization bearer header. This is my current script but it isn't loading anything. Would anyone be able to assist? I am very new to SSJS. Thanks!

<script runat="server">
Platform.Load("Core","1");
var apitoken = Variable.GetValue("@apitoken");
var url = "https://xxxxx.com.au/api/v1/events";
var headerNames = ("Authorization");
var headerValues = ("Bearer", apitoken);
var response = HTTP.Get(url, headerNames, headerValues);
Variable.SetValue("response",response.Content);

</script>
  • 1
    You should first of all have a space between “Bearer” and the token value, I.e. (“Bearer “, apitoken) – Lukas Lunow Aug 28 '19 at 5:45
5

Your header names and values need to be an array. See below example as per documentation

var url = 'http://www.example.com';
var headerNames = ["MyTestHeader1", "MyTestHeader2"];
var headerValues = ["MyTestValue1", "MyTestValue2"];
var response = HTTP.Get(url, headerNames, headerValues);

Also note Lucas' comment re space between bearer and token. In addition to this, to concatenate strings in javascript use + as such:

var headerValues = ["Bearer " + apitoken];

The above joins the string "Bearer " with the value of the apiToken variable and sets as first item in an array (indicated by the square brackets) which is assigned to the variable headerValues.

|improve this answer|||||

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.