I created an API Key by going to https://www.coinbase.com/home and clicking my profile picture in the top right and selected Settings. From there, I selected the API tab and ended up at https://www.coinbase.com/settings/api. I checked all wallets and all permissions when creating the API Key.
Following the instructions in Authorization and Authentication | Coinbase Cloud, I copied pasted the code, replaced the var secret = 'PYPd1Hv4J6/7x...';
with my secret, created a var COINBASE_API_KEY = "xxx"
variable and then added the following code:
var options = {
host: 'api.exchange.coinbase.com',
path: requestPath,
headers: {
"Accept": "application/json",
"Content-Type": "application/json",
"CB-ACCESS-KEY": COINBASE_API_KEY,
"CB-ACCESS-SIGN": cb_access_sign,
"CB-ACCESS-TIMESTAMP": cb_access_timestamp,
"CB-VERSION": "2023-01-08",
"User-Agent": "Node.js bot"
}
};
https.get(options, function(res) {
let data = [];
const headerDate = res.headers && res.headers.date ? res.headers.date : 'no response date';
console.log('Status Code:', res.statusCode);
console.log('Date in Response header:', headerDate);
res.on('data', chunk => {
data.push(chunk);
});
res.on('end', () => {
console.log('Response ended: ');
const users = JSON.parse(Buffer.concat(data).toString());
console.log(users);
});
}).on('error', err => {
console.log('Error: ', err.message);
});
I’m getting the following in the terminal:
Status Code: 401
Date in Response header: Thu, 12 Jan 2023 12:21:36 GMT
Response ended:
{ message: 'Invalid API Key' }
What am I missing?