API Reference: Coinbase using API Key (Node.js)
This guide covers interacting with the Coinbase API only for your Coinbase account.

If you’re looking to access Coinbase API on behalf of other users, head to the Coinbase using OAuth2 guide here.
Postman Request Collection: (Coming Soon)
Complete Source Code: https://gist.github.com/bdcorps/64b1258ad4670e7e39f0dd348cdd0a34
Getting Started
- Create a new Coinbase account.
- Head to the API section in the Settings and create an API Key.

3. Choose the appropriate API permissions as listed here.
4. After successfully creating the app, you will be presented with your API_KEY
and API_SECRET
. Keep them handy.
Make API Request
const createCBRequest = (method, url) => {
var timeInSeconds = parseInt((new Date()).getTime() / 1000);
var sigString = timeInSeconds + `${method}${url}`
var hmac = crypto.createHmac('sha256', API_SECRET);
signature = hmac.update(sigString).digest('hex');
const config = {
method,
url: `https://api.coinbase.com${url}`,
headers: {
'CB-ACCESS-KEY': API_KEY,
'CB-ACCESS-SIGN': signature,
'CB-ACCESS-TIMESTAMP': timeInSeconds
}
};
return axios(config);
}
Get User Details
app.get("/user", async (req, res) => {
try {
const response = await createCBRequest('GET', '/v2/user');
res.send({ response: response?.data })
} catch (e) {
console.log("Could not get user", e.response.data)
}
});
Get Primary Account
app.get("/account", async (req, res) => {
try {
const response = await createCBRequest('GET', '/v2/accounts/BTC');
res.send({ response: response?.data })
} catch (e) {
console.log("Could not get account", e.response.data)
}
});
Originally published at https://saasbase.dev on November 15, 2021.