Reputation: 21
I'm having some trouble using the binance pay api. My goal is to automate the payments for a platform that I'm building, for that I'm using withdrawal from spot wallet and I want to use binance pay.
Reading this Binance Pay API Documentation and Examples for signature and Steps to create API key and secret
I made this to create the request:
sign(query: string) {
const secretKey = 'XXX';
return createHmac('sha512', secretKey)
.update(query)
.digest('hex');
}
function makeRequest(endpoint, method, params = {}) {
const timestamp = Number(new Date().getTime()).toFixed(0);
const alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
let nonce = '';
for (let i = 0; i < 32; i++) {
nonce += alphabet[Math.floor(Math.random() * alphabet.length)];
}
const apiKey = 'XXXXX';
let payload = `nonce=${nonce}×tamp=${timestamp}`;
for (const key in params) {
if (Object.prototype.hasOwnProperty.call(params, key)) {
const value = params[key];
payload += `&${key}=${value}`
}
}
const signature = sign(payload);
const headers: AxiosRequestHeaders = {
'Content-Type': 'application/json',
'BinancePay-Timestamp': timestamp,
'BinancePay-Nonce': nonce,
'BinancePay-Certificate-SN': apiKey,
'BinancePay-Signature': signature,
'X-MBX-APIKEY': apiKey,
};
const url = 'https://bpay.binanceapi.com';
return this.httpService.request({
method,
url: `${url}/${endpoint}`,
params: {...params, timestamp, signature},
headers
});
}
No mater what I do, I keep getting "Invalid API-key, IP, or permissions for action" error message.
This works if I'm working with Binance Api (changing the sha512 to sha256 as stated in the docs).
The is how I'm calling it
makeRequest(
'binancepay/openapi/balance',
'POST',
{
wallet: 'FUNDING_WALLET',
currency: 'USDT'
}
)
It should return the state of my funding wallet.
My api key has all permisions active except for "Enable Margin, Loan, Refund and Transfer".
My apikey is from a personal account, is this why It's not working?
If anyone please could help me as I'm not understanding why is that is not valid my apiKey but with binance spot api is working
Also in Transfer fonds in Binance pay docs, it says that it requires a requestId, what request should I make to get this?
Upvotes: 1
Views: 1182
Reputation: 11
You use binance api key for binance pay. This are diff systems. Make acc in merchant.binance.com and get corect api keys from there.
Upvotes: 1