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);
Advertisement
Answer
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.