[SalesForce] Ampscript HTTP GET with Authorization Header

I'm trying to connect to a 3rd party API using HTTP GET, however the endpoint requires Header (Authorization: Bearer xxxxx) to be sent as part of the request.

In PHP, it would look something like this:

$opts = array(
    'http'=>array(
    'method'=>"GET",
    'header'=>"Authorization: Bearer ".$token)
);

The HTTP GET Documentation doesn't have anything on sending headers, however the HTTP POST2 method does include a header value. The API endpoint only accepts GET requests, so I can't use POST in this instance.

Any suggestions would be helpful.

Best Answer

Answer = Only possible with SSJS.
Original Solution here: HTTPGET Request in AMP Script with Bearer Token

%%[
SET @token = "ExampleAPIToken"
]%%

<script runat="server">
Platform.Load("Core","1.1.1");

var mytoken = Variable.GetValue("@token");
var url = "https://example.com/api/auth";
var headerNames = ["Accept", "Authorization"];
var headerValues = ["application/json", "Bearer "+mytoken];
var response = HTTP.Get(url, headerNames, headerValues);
Variable.SetValue("response",response.Content);

</script>

Response: %%=v(@response)=%%

Reference:
SSJS HTTPGET
SSJS Set/Get Values with Ampscript

Related Topic