Required parameter missing: account

473 Views Asked by At

I'm using Coinbase API, please visit here to know more about this API.

So, I'm running this program, you could take a look but it says:

{"success":false,"errors":["Required parameter missing: account"]}

Here is my program:

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;

import org.apache.commons.codec.binary.Hex;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;

import com.coinbase.api.Coinbase;
import com.coinbase.api.CoinbaseBuilder;

public class TransactionExample {

    static String API_KEY = "MY API KEY";

    static String API_SECRET = "MY API SECRET";

    public static String getHttp(String url, String body)
            throws InvalidKeyException, NoSuchAlgorithmException,
            ClientProtocolException, IOException {

        String nonce = String.valueOf(System.currentTimeMillis());
        String message = nonce + url + (body != null ? body : "");

        Mac mac = Mac.getInstance("HmacSHA256");
        mac.init(new SecretKeySpec(API_SECRET.getBytes(), "HmacSHA256"));
        String signature = new String(Hex.encodeHex(mac.doFinal(message.getBytes())));

        HttpRequestBase request;
        if (body == null || body.length() == 0)
            request = new HttpGet(url);
        else {
            HttpPost post = new HttpPost(url);
            post.setEntity(new StringEntity(body));
            request = post;
        }
        request.setHeader("ACCESS_KEY", API_KEY);
        request.setHeader("ACCESS_SIGNATURE", signature);
        request.setHeader("ACCESS_NONCE", nonce);

        HttpClient httpClient = HttpClientBuilder.create().build();
        HttpResponse response = httpClient.execute(request);

        HttpEntity entity = response.getEntity();
        if (entity != null)
            return EntityUtils.toString(entity);
        return null;
    }
    
    public static void main(String[] args) throws InvalidKeyException, NoSuchAlgorithmException, ClientProtocolException, IOException{
        
        System.out.println(getHttp("https://api.coinbase.com/v1/accounts", "{'account':{'name':'Savings Wallet'}}")); 
    }
}

Please help!

Surely, help would be appreciated!!

1

There are 1 best solutions below

0
On

You need to swap out the place holder text for your actual API Keys here:

 static String API_KEY = "MY API KEY";

 static String API_SECRET = "MY API SECRET";

You can get them at https://www.coinbase.com/settings/api.

Although, if you're just starting out, I recommend testing with the Sandbox API first to avoid any security risks. If your API keys have permissions to buy/sell or send money out of your account, any one who has them can do so.

When using the Sandbox API, you'll need to change the URL from https://api.coinbase.com/v1/accounts to https://api.sandbox.coinbase.com/v1/accounts.

Also, we've released v2 of our API, which is far more awesome, but would require some other modifications to this script.