I am trying to get my bank balances in Google Sheets and decided to use this script https://github.com/bradjasper/ImportJSON to pull data from my Investec bank account via the API here: https://developer.investec.com/programmable-banking/#authorization
I am calling the function ImportJSONBasicAuth("https://openapi.investec.com/identity/v2/oauth2/token","{username}","{secret}","","") with my username and secret, in my Google Sheet... But I get an error as follows
Error Exception: Request failed for https://openapi.investec.com returned code 400 (line 220).
Any ideas what I might be doing wrong?
EDIT
Digging a little deeper into the error...
This is the function I'm calling
function ImportJSONBasicAuth(url, username, password, query, parseOptions) {
var encodedAuthInformation = Utilities.base64Encode(username + ":" + password);
var header = {headers: {Authorization: "Basic " + encodedAuthInformation}};
return ImportJSONAdvanced(url, header, query, parseOptions, includeXPath_, defaultTransform_);
}
Which calls this function in turn - which has the line producing the error i.e. line 220 commented below
function ImportJSONAdvanced(url, fetchOptions, query, parseOptions, includeFunc, transformFunc) {
var jsondata = UrlFetchApp.fetch(url, fetchOptions); //line 220
var object = JSON.parse(jsondata.getContentText());
return parseJSONObject_(object, query, parseOptions, includeFunc, transformFunc);
}
I found a function ImportJSONViaPost in the code, so I tried to combine that with the function ImportJSONBasicAuth that I was using, but also get the same error.
Here is the combined function:
function ImportJSONBasicAuthViaPost(url, username, password, payload, fetchOptions, query, parseOptions) {
var postOptions = parseToObject_(fetchOptions);
var encodedAuthInformation = Utilities.base64Encode(username + ":" + password);
var APIKey = "Basic " + encodedAuthInformation;
if (postOptions["headers.Authorization"] == null) {
postOptions["headers.Authorization"] = APIKey;
}
if (postOptions["method"] == null) {
postOptions["method"] = "POST";
}
if (postOptions["payload"] == null) {
postOptions["payload"] = payload;
}
if (postOptions["contentType"] == null) {
postOptions["contentType"] = "application/x-www-form-urlencoded";
}
if (postOptions["contentType"] == null) {
postOptions["contentType"] = "application/x-www-form-urlencoded";
}
convertToBool_(postOptions, "validateHttpsCertificates");
convertToBool_(postOptions, "useIntranet");
convertToBool_(postOptions, "followRedirects");
convertToBool_(postOptions, "muteHttpExceptions");
return ImportJSONAdvanced(url, postOptions, query, parseOptions, includeXPath_, defaultTransform_);
}