I have the below working PHP code that calls an API. The API will use some of the headers and encrypt them to compare with the Client-Signature which is also one item in the header.
I translated to Google App Script. But unfortunately I am getting a signature error for the App Script code.
My question is, would Google App Script render the headers the same way at the PHP code shown? Because, all others issues ruled out, I am doubting that the way headers are rendered in the HTTP request may be causing the signature issue.
If you see an other issue, please let me know. I am totally stuck here.
$requestId = "**";
$tokenID = "**";
$signature = "**";
$ch = curl_init();
$url = "https://public-api.sandbox.bunq.com/v1/user/3079/monetary-account";
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HEADER,1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$headers = [
"Cache-Control: no-cache",
"Content-Type: application/json",
"User-Agent: VBA-Web v4.1.5 (https://github.com/VBA-tools/VBA-Web)",
"X-Bunq-Geolocation: 0 0 0 0 NL",
"X-Bunq-Language: en_US",
"X-Bunq-Region: en_US",
"X-Bunq-Client-Request-Id: " . $requestId,
"X-Bunq-Client-Authentication: " . $tokenID,
"X-Bunq-Client-Signature: " . $signature
];
var_dump( $headers);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$server_output = curl_exec ($ch);
curl_close ($ch);
var_dump ( $server_output) ;
Google App Script Code:
var requestId = "**";
var url = "https://public-api.sandbox.bunq.com/v1/user/3079/monetary-account";
var tokenID = "**";
var signature = "**";
var RequestHeader = {
"Cache-Control" : "no-cache",
"Content-Type" : "application/json" ,
"User-Agent" : "VBA-Web v4.1.5 (https://github.com/VBA-tools/VBA-Web)",
"X-Bunq-Geolocation" : "0 0 0 0 NL",
"X-Bunq-Language" : "en_US",
"X-Bunq-Region" : "en_US",
"X-Bunq-Client-Request-Id" : requestId,
"X-Bunq-Client-Authentication" : tokenID,
"X-Bunq-Client-Signature" : signature
};
var options = {
"method": "GET",
"headers": RequestHeader,
muteHttpExceptions : true
}
var response = UrlFetchApp.fetch(url, options);
Logger.log(response );
getRequestclass method and logging it (preferably to Stackdriver). You can then send that request with thefetchAllclass method.