Hi, I’ve set up the binance API using their testnet in postman, and got the API working perfectly fine with test data. It has a pre-request script which I am having trouble replicating in bubble. I have attached the postman collection and screenshots of my setup in the bubble API. The API keys in these images are testnet data.
The pre-request script is
const ts = Date.now();
pm.environment.set(“timestamp”, ts);
let paramsObject = {};
const binance_api_secret = pm.environment.get(“binance-api-secret”);
const parameters = pm.request.url.query;
parameters.map((param) => {
if (param.key != 'signature' &&
param.key != 'timestamp' &&
!is_empty(param.value) &&
!is_disabled(param.disabled)) {
paramsObject[param.key] = param.value;
//console.log(encodeURIComponent(param.value));
//pm.environment.set(param.key, encodeURIComponent(param.value));
}
})
Object.assign(paramsObject, {‘timestamp’: ts});
if (binance_api_secret) {
const queryString = Object.keys(paramsObject).map((key) => {
return `${key}=${paramsObject[key]}`;
}).join('&');
console.log(queryString);
const signature = CryptoJS.HmacSHA256(queryString, binance_api_secret).toString();
pm.environment.set("signature", signature);
}
function is_disabled(str) {
return str == true;
}
function is_empty(str) {
if (typeof str == 'undefined' ||
!str ||
str.length === 0 ||
str === "" ||
!/[^\s]/.test(str) ||
/^\s*$/.test(str) ||
str.replace(/\s/g,"") === "")
{
return true;
}
else
{
return false;
}
}
When I try run it currently it says the timestamp and signature fields are empty. I also have to put my binance secret key somewhere. Is there an easy way to run the pre-request script in bubble?
Appreciate any help
Thanks