I’m trying to get any response from the Bybit API using google apps script. I have been able to get response from the API when using simple nodeJS code. But when converting the syntax to google apps script I get a strange 403 error.
I have tried multiple different syntax to make this work. After reading through countless documentation and looking how other people get responses from API’s using app script, I have code that should work but doesn’t, I feel stuck now.
This is my current Google Apps Script code, I have changed the values of apiKey and secret for this:
var apiKey = 'XXXXX';
var timestamp = new Date().getTime().toString();
var recvWindow = '5000';
var parameters = 'accountType=SPOT';
var message = timestamp + apiKey + recvWindow + parameters;
var url = 'https://api.bybit.com/v5/asset/transfer/query-account-coins-balance?accountType=SPOT';
const secret = 'XXXXXXXXXXXX';
function createSign() {
var signatureBytes = Utilities.computeHmacSha256Signature(message, secret);
var signature = signatureBytes.reduce(function(str, byte) {
return str + ('0' + (byte & 0xFF).toString(16)).slice(-2);
}, '');
Logger.log(signature);
return signature.toString();
}
function main() {
var config = {
method: 'GET',
headers: {
'X-BAPI-API-KEY': apiKey,
'X-BAPI-TIMESTAMP': timestamp,
'X-BAPI-RECV-WINDOW': recvWindow,
'X-BAPI-SIGN': createSign()
},
muteHttpExceptions: true
}
var response = UrlFetchApp.fetch(url, config);
var response2 = UrlFetchApp.getRequest(url, config);
Logger.log(response2);
Logger.log(response);
}
And this is what I get:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<TITLE>ERROR: The request could not be satisfied</TITLE>
</HEAD><BODY>
<H1>403 ERROR</H1>
<H2>The request could not be satisfied.</H2>
<HR noshade size="1px">
The Amazon CloudFront distribution is configured to block access from your country.
We can't connect to the server for this app or website at this time. There might be too much traffic or a configuration error. Try again later, or contact the app or website owner.
<BR clear="all">
If you provide content to customers through CloudFront, you can find steps to troubleshoot and help prevent this error by reviewing the CloudFront documentation.
<BR clear="all">
<HR noshade size="1px">
<PRE>
Generated by cloudfront (CloudFront)
Request ID: ns9XoZU762a7V7mCAE07rgmK3dWkOtjKK9LHuyNjyTW14CQkdvUGtw==
</PRE>
<ADDRESS>
</ADDRESS>
</BODY></HTML>
marremarräng is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.