-2

I was using below code to get the response but I Was getting the 403 error

URL url = new URL ("https://api.commerce.coinbase.com/checkouts");

 Map map=new HashMap();

 HttpURLConnection connection = (HttpURLConnection) url.openConnection();
 connection.setRequestMethod("POST");
 connection.setDoOutput(true);
Aman Mate
  • 3
  • 2

2 Answers2

1

From https://commerce.coinbase.com/docs/api/

Most requests to the Commerce API must be authenticated with an API key. You can create an API key in your Settings page after creating a Coinbase Commerce account.

You would need to provide minimal set of information to API in order for it to respond back with success code 200.

Rupesh
  • 2,627
  • 1
  • 28
  • 42
  • POST Response Code : 403 POST Response Message : Forbidden java.io.IOException: Server returned HTTP response code: 403 for URL: https://api.commerce.coinbase.com/checkouts at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) – Aman Mate Apr 05 '20 at 14:15
0

Yes, but it looks like you aren't providing enough information. There are two header fields that need to be supplied as well. These are X-CC-Api-Key which is your API key and X-CC-Version. See the link below.

https://commerce.coinbase.com/docs/api/#introduction

Header fields can be provided to HttpURLConnection using the addRequestProperty https://docs.oracle.com/javase/8/docs/api/java/net/URLConnection.html#addRequestProperty-java.lang.String-java.lang.String-

URL url = new URL("https://api.commerce.coinbase.com/checkouts");

HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.addRequestProperty("X-CC-Api-Key", "YourSuperFancyAPIKey");
connection.addRequestProperty("X-CC-Version", "2018-03-22");
connection.setDoOutput(true);

You also want to be careful about what method you use. You are supplying a POST method in your example. This probably not what you want to start with. If you send a GET method you will receive back a list of all checks. This will be a good place to start.

https://commerce.coinbase.com/docs/api/#checkouts

  • GET to retrieve a list of checkouts
  • POST to create a new checkout
  • PUT to update a checkout
  • DELETE to delete a checkout

This type of API is known as REST.

Chuck Lowery
  • 902
  • 6
  • 17