Required parameter missing account error

0 votes

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"]}

I am using the following code:

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'}}")); 
    }
}
Aug 30, 2018 in Blockchain by digger
• 26,740 points
1,579 views

1 answer to this question.

0 votes

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.

answered Aug 30, 2018 by slayer
• 29,370 points

Related Questions In Blockchain

0 votes
1 answer

Error: t: Instance org.acme.seller.Car#HW7722 missing required field oldOwner

This error occurs if you have added a ...READ MORE

answered Jun 21, 2018 in Blockchain by Christine
• 15,790 points

edited Jun 21, 2018 by Christine 1,442 views
0 votes
1 answer

Error while trying to create dir if missing: mkdir /var/hyperledger: permission denied

The following commands should help: sudo mkdir -p ...READ MORE

answered Jul 6, 2018 in Blockchain by Christine
• 15,790 points
1,930 views
0 votes
1 answer

Hyperledger Fabric: build error "files are missing SPDX-License-Identifier headers"

Try this: make peer orderer peer-docker orderer-docker tools-docker ...READ MORE

answered Oct 30, 2018 in Blockchain by Omkar
• 69,220 points
826 views
0 votes
1 answer

403 forbidden error coinbase api

I had a similiar issue connecting this API, ...READ MORE

answered Aug 28, 2018 in Blockchain by digger
• 26,740 points
2,662 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,947 views
+1 vote
3 answers

Removing double quotes from a string from JSON response in PHP

Just remove the json_encode call, and it should work: $resp ...READ MORE

answered Sep 12, 2018 in Blockchain by digger
• 26,740 points
45,301 views
0 votes
1 answer

How do I add multiple recipients for transactions via Blockchain API?

Convert the recipes into JSON objects. x = ...READ MORE

answered Jul 6, 2018 in Blockchain by Perry
• 17,100 points
930 views
0 votes
1 answer

"set RNG(RandomUtils.Random) before generating random numbers" error

Use the following code, you just have ...READ MORE

answered Jul 5, 2018 in Blockchain by slayer
• 29,370 points
822 views
0 votes
1 answer

Error connecting due to rpc error

In the previous version, this problem was ...READ MORE

answered Jul 6, 2018 in Blockchain by slayer
• 29,370 points
824 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP