Invalid_token: The access token is invalid

Trying to create a transaction through coinbase’s api to send crypto to an outside address. Multiple other endpoints are working fine and I have no problems with them but this specific one is giving me an error: { id: 'invalid_token', message: 'The access token is invalid' }

const secrets = require('./2fasecrets.json');

const crypto = require('crypto');
const axios = require('axios');

var timestamp = Math.floor(Date.now() / 1000);

var message = timestamp + "POST" + "/v2/accounts/`${secrets.account_id}`/transactions";
//console.log(message);

axios.post('https://api.coinbase.com/v2/accounts/`${secrets.account_id}`/transactions', {
    headers: {
        'CB-ACCESS-KEY': secrets.coinbase_wallet_api_key,
        'CB-ACCESS-SIGN': crypto.createHmac('sha256', secrets.coinbase_wallet_api_secret).update(message).digest('hex'),
        'CB-ACCESS-TIMESTAMP': timestamp,
        'CB-VERSION': '2023-06-15'
    },
    data: {
        "type": "send",
        "to": "LafAM2yAF7TrfSFu2LMCx8ynj3tgPidSUL",
        "amount": "0.010391769718383041",
        "currency": "LTC",
        "idem": "1111sss"
    }
})
.then((response) => {
    console.log(response.data.data)
})

My secrets.account_id is the ID seen for LTC in the /v2/accounts/ GET request. I also tried to use my account’s ID to no luck.

I’m authenticating using API KEY, not oAUTH

Hey @dvnt,

Can you please confirm if you still face this issue. Also, please do check your API Key Authentication per this document: API Key Authentication | Coinbase Cloud

1 Like