Hi James,
Thanks for the reply.
Unfortunately I can't guarantee that the @ character won't be in a password so calling a separate function for that. But good to know for future reference!
I've been trying the JSON object previously and couldn't make it work. Using httpbin.org/get, I can see that although you can change the Content-Type Header data, the Header remains as Content-Type.
I have managed a work around by fiddling with the asyncHTTP Visual Block XML to allow me to add any headers I want and it works fine.
Cheers,
Chris
------------------------------
Chris Mason
ES BROADCAST LTD
------------------------------
Original Message:
Sent: 05-05-2021 15:59
From: James Peltzer
Subject: HTTP Get with Authorization Header
Hi Chris
Provided your password does not have a '@' character in it, we do have a shortcut to use a base64 authentication. Just use:
var credentials = "Username@username.com" + ":" + "Password"
var requestURL = "https://" + credentials + "@app.singular.live/apiv1/appinstances"
ogscript.debug(credentials);
var creds = "Basic " + params.getValue('Base64', 0);
ogscript.asyncHTTP(requestURL, "GET", "application/json" , null, null);
Another option you can use is to replace the content-type argument with a JSON object containing any headers you wish to send:
var requestURL = "https://app.singular.live/apiv1/appinstances"
var credentials = "Username@username.com" + ":" + "Password"
ogscript.debug(credentials);
var credentials64 = base64Encode(credentials)
ogscript.debug("base64Encode =" + credentials64);
params.setValue('Base64', 0, credentials64);
var creds = "Basic " + params.getValue('Base64', 0);
var headers = {}
headers["Authorization"] = creds;
headers["Content-Type"] = "application/json";
ogscript.asyncHTTP(requestURL, "GET", headers , null, null);
Cheers
James
------------------------------
James Peltzer
Ross Video
Original Message:
Sent: 05-05-2021 04:34
From: Chris Mason
Subject: HTTP Get with Authorization Header
Hi All,
Could someone help me out?
I've searched the board and found a few posts relating a HTTP Post using headers but I just can't make it work with a GET.
I need to send an HTTP Get with an authorization header for a web API.
Here's my code:
var requestURL = "https://app.singular.live/apiv1/appinstances"
var credentials = "Username@username.com" + ":" + "Password"
ogscript.debug(credentials);
var credentials64 = base64Encode(credentials)
ogscript.debug("base64Encode =" + credentials64);
params.setValue('Base64', 0, credentials64);
var creds = "Basic " + params.getValue('Base64', 0);
var headers = {}
headers["Authorization"] = creds;
ogscript.asyncHTTP(requestURL, "GET", "application/json" , null, null);
var headerstring = JSON.stringify(headers)
ogscript.debug("headers =" + headerstring);
In this state the server returns an unauthorised message which I'd expect, but trying to insert my "headers" array anywhere into this command makes it unrecognizable to the server.
Cheers,
Chris
------------------------------
Chris Mason
ES BROADCAST LTD
------------------------------