For developers eager to hit the ground running with the CoinMarketCap API here are a few quick steps to make your first call with the API.
- Sign up for a free Developer Portal account. You can sign up at pro.coinmarketcap.com - This is our live production environment with the latest market data. Select the free
Basic plan if it meets your needs or upgrade to a paid tier.
- Copy your API Key. Once you sign up you'll land on your Developer Portal account dashboard. Copy your API from the
API Key box in the top left panel.
- Make a test call using your key. You may use the code examples provided below to make a test call with your programming language of choice. This example fetches all active cryptocurrencies by market cap and return market values in USD.
Be sure to replace the API Key in sample code with your own and use API domain pro-api.coinmarketcap.com or use the test API Key b54bcf4d-1bca-4e8e-9a24-22ff2c3d462c for sandbox-api.coinmarketcap.com testing with our sandbox environment. Please note that our sandbox api has mock data and should not be used in your application.
- Postman Collection To help with development, we provide a fully featured postman collection that you can import and use immediately! Read more here.
- Implement your application. Now that you've confirmed your API Key is working, get familiar with the API by reading the rest of this API Reference and commence building your application!
Note: Making HTTP requests on the client side with Javascript is currently prohibited through CORS configuration. This is to protect your API Key which should not be visible to users of your application so your API Key is not stolen. Secure your API Key by routing calls through your own backend service.
View Quick Start Code Examples
cURL command line
curl -H "X-CMC_PRO_API_KEY: b54bcf4d-1bca-4e8e-9a24-22ff2c3d462c" -H "Accept: application/json" -d "start=1&limit=5000&convert=USD" -G https://sandbox-api.coinmarketcap.com/v1/cryptocurrency/listings/latest
Node.js
/* Example in Node.js */
const axios = require('axios');
let response = null;
new Promise(async (resolve, reject) => {
try {
response = await axios.get('https://sandbox-api.coinmarketcap.com/v1/cryptocurrency/listings/latest', {
headers: {
'X-CMC_PRO_API_KEY': 'b54bcf4d-1bca-4e8e-9a24-22ff2c3d462c',
},
});
} catch(ex) {
response = null;
// error
console.log(ex);
reject(ex);
}
if (response) {
// success
const json = response.data;
console.log(json);
resolve(json);
}
});
Python
#This example uses Python 2.7 and the python-request library.
from requests import Request, Session
from requests.exceptions import ConnectionError, Timeout, TooManyRedirects
import json
url = 'https://sandbox-api.coinmarketcap.com/v1/cryptocurrency/listings/latest'
parameters = {
'start':'1',
'limit':'5000',
'convert':'USD'
}
headers = {
'Accepts': 'application/json',
'X-CMC_PRO_API_KEY': 'b54bcf4d-1bca-4e8e-9a24-22ff2c3d462c',
}
session = Session()
session.headers.update(headers)
try:
response = session.get(url, params=parameters)
data = json.loads(response.text)
print(data)
except (ConnectionError, Timeout, TooManyRedirects) as e:
print(e)
PHP
/**
* Requires curl enabled in php.ini
**/
<?php
$url = 'https://sandbox-api.coinmarketcap.com/v1/cryptocurrency/listings/latest';
$parameters = [
'start' => '1',
'limit' => '5000',
'convert' => 'USD'
];
$headers = [
'Accepts: application/json',
'X-CMC_PRO_API_KEY: b54bcf4d-1bca-4e8e-9a24-22ff2c3d462c'
];
$qs = http_build_query($parameters); // query string encode the parameters
$request = "{$url}?{$qs}"; // create the request URL
$curl = curl_init(); // Get cURL resource
// Set cURL options
curl_setopt_array($curl, array(
CURLOPT_URL => $request, // set the request URL
CURLOPT_HTTPHEADER => $headers, // set the headers
CURLOPT_RETURNTRANSFER => 1 // ask for raw response instead of bool
));
$response = curl_exec($curl); // Send the request, save the response
print_r(json_decode($response)); // print json decoded response
curl_close($curl); // Close request
?>
Java
/**
* This example uses the Apache HTTPComponents library.
*/
import org.apache.http.HttpEntity;
import org.apache.http.HttpHeaders;
import org.apache.http.NameValuePair;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
public class JavaExample {
private static String apiKey = "b54bcf4d-1bca-4e8e-9a24-22ff2c3d462c";
public static void main(String[] args) {
String uri = "https://sandbox-api.coinmarketcap.com/v1/cryptocurrency/listings/latest";
List<NameValuePair> paratmers = new ArrayList<NameValuePair>();
paratmers.add(new BasicNameValuePair("start","1"));
paratmers.add(new BasicNameValuePair("limit","5000"));
paratmers.add(new BasicNameValuePair("convert","USD"));
try {
String result = makeAPICall(uri, paratmers);
System.out.println(result);
} catch (IOException e) {
System.out.println("Error: cannont access content - " + e.toString());
} catch (URISyntaxException e) {
System.out.println("Error: Invalid URL " + e.toString());
}
}
public static String makeAPICall(String uri, List<NameValuePair> parameters)
throws URISyntaxException, IOException {
String response_content = "";
URIBuilder query = new URIBuilder(uri);
query.addParameters(parameters);
CloseableHttpClient client = HttpClients.createDefault();
HttpGet request = new HttpGet(query.build());
request.setHeader(HttpHeaders.ACCEPT, "application/json");
request.addHeader("X-CMC_PRO_API_KEY", apiKey);
CloseableHttpResponse response = client.execute(request);
try {
System.out.println(response.getStatusLine());
HttpEntity entity = response.getEntity();
response_content = EntityUtils.toString(entity);
EntityUtils.consume(entity);
} finally {
response.close();
}
return response_content;
}
}
C#
using System;
using System.Net;
using System.Web;
class CSharpExample
{
private static string API_KEY = "b54bcf4d-1bca-4e8e-9a24-22ff2c3d462c";
public static void Main(string[] args)
{
try
{
Console.WriteLine(makeAPICall());
}
catch (WebException e)
{
Console.WriteLine(e.Message);
}
}
static string makeAPICall()
{
var URL = new UriBuilder("https://sandbox-api.coinmarketcap.com/v1/cryptocurrency/listings/latest");
var queryString = HttpUtility.ParseQueryString(string.Empty);
queryString["start"] = "1";
queryString["limit"] = "5000";
queryString["convert"] = "USD";
URL.Query = queryString.ToString();
var client = new WebClient();
client.Headers.Add("X-CMC_PRO_API_KEY", API_KEY);
client.Headers.Add("Accepts", "application/json");
return client.DownloadString(URL.ToString());
}
}
Go
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"net/url"
"os"
)
func main() {
client := &http.Client{}
req, err := http.NewRequest("GET","https://sandbox-api.coinmarketcap.com/v1/cryptocurrency/listings/latest", nil)
if err != nil {
log.Print(err)
os.Exit(1)
}
q := url.Values{}
q.Add("start", "1")
q.Add("limit", "5000")
q.Add("convert", "USD")
req.Header.Set("Accepts", "application/json")
req.Header.Add("X-CMC_PRO_API_KEY", "b54bcf4d-1bca-4e8e-9a24-22ff2c3d462c")
req.URL.RawQuery = q.Encode()
resp, err := client.Do(req);
if err != nil {
fmt.Println("Error sending request to server")
os.Exit(1)
}
fmt.Println(resp.Status);
respBody, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(respBody));
}