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>
Best Answer
Your header names and values need to be an array. See below example as per documentation
Also note Lucas' comment re space between bearer and token. In addition to this, to concatenate strings in javascript use
+
as such: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 variableheaderValues
.