2

I am working on a project that requires using Coinbase API v2 to make a transfer between two wallets. When I make a call to the API (https://api.coinbase.com/v2/accounts/:account_id/transactions), I am receiving a 200 Success Response Code with an empty body. This would be fine, but the actual transfer is not occurring on my account. The API documentation suggests a Response Code of 201 should be expected, with a receipt showing all pertinent information of the transaction. None of that is happening.

The expected arguments are:

  • Type (in this case, it will always be "transfer")
  • To (the account ID)
  • Amount (A double value)
  • Currency (Currency unit of the amount to be transferred)

I have systematically changed every variable of my request, every body/header element, changing account IDs (to and from), inputting invalid currencies, amounts, etc. Each time, a 404 Bad Request is returned, telling me where the error is. I also make several other API calls at other points, each requiring the Authorization Headers, and those pass and return the expected data. This means my current setup for making the API calls is correct, at least in terms of the code.

Here is my current calling method:

Main:

    JSONObject j = APICallBuilder.convertCurrency(CurrencyHandler.findCurrencyID("ETH"), CurrencyHandler.findCurrencyID("BTC"), 54);
    System.out.println(j.toString(1));

CurrencyHandler:

    public static String findCurrencyID(String code) {
        String ID = "Invalid code";
        for(int i = 0; i < currencyArray.length; i++) {
            if(currencyArray[i].getCode().equals(code)) {
                ID = currencyArray[i].getID();
            }
        }
        return ID;
    }

I obtain the ID value directly from the https://api.coinbase.com/v2/accounts call, and I am certain it is correct, as incorrect values (to or from) will cause a 404 Bad Request Response.I tested this by retaining the same format of the IDs, but replacing a single character with another character (ensuring the character was between 0-f, just like the original ID).

API Call:

    public static JSONObject convertCurrency(String fromCode, String toCode, double amount) {
        String url = requests.getJSONObject("convert").getString("requestPath");
        String requestPath = "/v2/accounts/${var}/transactions";
        String method = "POST";
        String timestamp = getEpochTime();

        url = url.replace("${var}", fromCode);
        requestPath = requestPath.replace("${var}", fromCode);

        JSONObject bodyFormatter = new JSONObject();
        bodyFormatter.put("type", "transfer");
        bodyFormatter.put("to", toCode);
        bodyFormatter.put("amount", amount);
        bodyFormatter.put("currency", "USD");


        String body = bodyFormatter.toString();
        String header = HeaderGenerator.getHMACHeader(secretKey, timestamp, method, requestPath, body);

        RequestBody rb = RequestBody.create(JSON, bodyFormatter.toString());

        Request request = new Request.Builder()
                .addHeader(CB_ACCESS_KEY, accessKey)
                .addHeader(CB_ACCESS_SIGN, header)
                .addHeader(CB_ACCESS_TIMESTAMP, timestamp)
                .addHeader(CB_VERSION, getDate())
                .addHeader("Accept", "application/json")
                .addHeader("Content-Type", "application/json")
                .url(url)
                .post(rb)
                .build();

        Response res;
        JSONObject par = null;
        try {
            res = APICommunicator.sendRequest(request);
            String data = res.body().string();
            System.out.println(res.code());
            par = new JSONObject(data);
        } catch (IOException e) {
            e.printStackTrace();
            ErrorLogger.logException(e);
        }

        return par;
    }

Is there something about the API I am missing? I have read through the entire documentation several times, and I cannot find how or why this is occurring.

jlars789
  • 155
  • 9
  • Did you find an answer for you question jlars789 ? – CMJ Feb 20 '21 at 17:10
  • I'm having the same issue using a python approach -- response code of 200 but no response text (more accurately, a response of `{}`), while other endpoint requests function correctly. – Bilbottom Apr 05 '21 at 20:49
  • Did you find an answer? I have exactly the same problem. – Simon2215 Nov 01 '21 at 17:32

1 Answers1

0

Have you tried enabling "Instant sends" on the receiver account?

Refs: https://help.coinbase.com/en/coinbase/trading-and-funding/sending-or-receiving-cryptocurrency/instant-sends

Jarod Denison
  • 21
  • 1
  • 1