Coinbase Sandbox API Unauthorised API Key

Viewed 89

I have generated a number of API keys for coinbase sandbox and am trying to use them to get the list of user accounts. However I keep getting the same error 401 Unauthorised API key.

I have read through the documentation and am quite sure im doing everything right.

Below is my code. If anyone can see whats wrong it would be greatly appreciated.

public CommandLineRunner run(RestTemplate restTemplate) throws Exception {
        return args -> {

            // request url
            String url = "https://api.coinbase.com/v2/accounts";

            long unixTime = Instant.now(clock).getEpochSecond();

            String sha256hex = Hashing.sha256()
                    .hashString("rv3fSnIVN5R0DzINY6RRAronuWLAxPLV48XnGOFP+WL8Lh22bOJ0BvwyGH37hZ2tLRuTsjSnGCmK/dDM9FKNcw==", StandardCharsets.UTF_8)
                    .toString();

            // create headers
            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.APPLICATION_JSON);
            headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
            headers.set("CB-ACCESS-KEY", "63d1342304ba4d7fcc1297bf26a90418");
            headers.set("CB-ACCESS-SIGN", sha256hex);
            headers.set("CB-ACCESS-TIMESTAMP",""+unixTime);
            headers.set("CB-ACCESS-PASSPHRASE","xdeqz62oak");

            // build the request
            HttpEntity request = new HttpEntity(headers);


            ResponseEntity<LiveData> liveData = restTemplate.exchange(
                    url,
                    HttpMethod.GET,
                    request,
                    LiveData.class);
            log.info(liveData.toString());
        };
0 Answers
Related