The title sums up my problems. I used the sms code for 2FA in the POST header and got a 401 Unauthorized Response. According to the docs , I'm supposed to get a 201 response. Could anyone possible guess what's missing from my POST request? Could it be because I am testing on my local machine? BTW I am using axios as my HTTP client for this Node.js project.
config: {
url: 'https://api.coinbase.com/v2/accounts/1456cc98-dd71-5ae3-8e90-c04d1d87e2b8/transactions',
method: 'post',
data: '{"type":"send","to":"3MLCRpMDoC3BFBsaSLNimWfJFvsMVBq4Ac","amount":"0.0000018","currency":"BTC"}',
headers: {
Accept: 'application/json, text/plain, */*',
'Content-Type': 'application/json;charset=utf-8',
'CB-2FA-TOKEN': '4152880',
'User-Agent': 'axios/0.21.1',
'Content-Length': 95
}, .....
I figured it out!
module.exports.replaySendMoney = function replaySendMoney(smsCode){
// in the future access token will be stored and retrieved from database
var Client = require('coinbase').Client;
let accessToken = '2aac7a723eb58bfaf13a9073ac7b6972dca071f14fa0abbc766e9ed9f60be596';
let refreshToken = '17a609e13c7608ecd499a1be502da18a7096ccf2d5fe9f40fca2b87501f7c233';
var client = new Client({'accessToken': accessToken, 'refreshToken': refreshToken});
client.getAccount('BTC', function(err,acct){
// REQUIRES 2FA
acct.sendMoney({
'to': '3MLCRpMDoC3AFBsaSLNimWfJFvsMVBq4Ac',
'amount': '0.0000018',
'currency': 'BTC',
'two_factor_token' : smsCode // MISSING PARAMETER
}, function(err, txt){
console.log(err);
console.log(txt);
res.render('authPurchase', {});
});
});
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.