Unauthorized error using axios while curl request works

Below is the sample code I’m using to generate JWT token and same JWT token works using curl request but throws “Unauthorized” error while using axios

const { sign } = require('jsonwebtoken');
const axios = require('axios');

const key_name       = 'organizations/{org_id}/apiKeys/{key_id}';
const key_secret = '-----BEGIN EC PRIVATE KEY-----\nYOUR PRIVATE KEY\n-----END EC PRIVATE KEY-----\n';
const request_method = 'GET';
const url = 'api.coinbase.com';
const request_path = '/api/v3/brokerage/accounts';
const service_name = "retail_rest_api_proxy"

const algorithm = 'ES256';
const uri = request_method + ' ' + url + request_path;

const token = sign(
            aud: [service_name],
            iss: 'coinbase-cloud',
            nbf: Math.floor(Date.now() / 1000),
            exp: Math.floor(Date.now() / 1000) + 10,
            sub: key_name,
            header: {
                kid: key_name,
                nonce: Math.floor(Date.now() / 1000).toString(),

let config = {
        method: 'GET',
        url: 'https://api.coinbase.com/api/v3/brokerage/accounts',
        headers: { 
            'Content-Type': 'application/json',
            'Authorization': 'Bearer ' + token

    .then((response) => {
        responseBody = JSON.stringify(response.data);
    .catch((error) => {

With that you mean token generated by sign function?

With curl, do you also send content type header? It is GET request, there is no body, maybe sending that header causes problem?

Right token generated by sign function, and tried without content-type header value but still getting same result.

This is resolved as my OS time was incorrect

If time was problem then why curl did succeed? You told you used same token!?