# How to query CoinMarketCap with Julia (rest api)

**URL:** <https://discourse.julialang.org/t/how-to-query-coinmarketcap-with-julia-rest-api/71406>\
**Category:** General Usage\
**Tags:** question\
**Created:** [November 12, 2021, 10:00pm UTC](https://discourse.julialang.org/t/how-to-query-coinmarketcap-with-julia-rest-api/71406 "2021-11-12T22:00:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [November 12, 2021, 10:00pm UTC](https://discourse.julialang.org/t/how-to-query-coinmarketcap-with-julia-rest-api/71406/1 "2021-11-12T22:00:20Z")

</div>

Hello,

How can I translate the following request to a Julia function:

```julia
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.coinmarketcap.com/v1/cryptocurrency/listings/latest

```

Same code in Python:

```julia
#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)

```

Any hints welcome!

For testing the test API Key `b54bcf4d-1bca-4e8e-9a24-22ff2c3d462c` for `sandbox-api.coinmarketcap.com` can be used.

First question: Any package that I should try?

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [November 12, 2021, 10:51pm UTC](https://discourse.julialang.org/t/how-to-query-coinmarketcap-with-julia-rest-api/71406/2 "2021-11-12T22:51:24Z")

</div>

OK, this is how far I got so far:

```julia
using HTTP

const URL = "https://sandbox-api.coinmarketcap.com/v1/cryptocurrency/listings/latest"

function make_API_call(url)
    try
        response = HTTP.get(url)
        return String(response.body)
    catch e
        return "Error occurred : $e"
    end
end

response = make_API_call(URL)
println(response)

```

But how can I pass the headers and the parameters?

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [November 12, 2021, 11:37pm UTC](https://discourse.julialang.org/t/how-to-query-coinmarketcap-with-julia-rest-api/71406/3 "2021-11-12T23:37:24Z")

</div>

Finally it is working: 🙂

```julia
using HTTP

const URL = "https://sandbox-api.coinmarketcap.com/v1/cryptocurrency/listings/latest"

function make_API_call(url)
    try
        response = HTTP.get(url, ["Accepts" => "application/json", "X-CMC_PRO_API_KEY" => "b54bcf4d-1bca-4e8e-9a24-22ff2c3d462c"], "{'start': '1', 'limit': '5000', 'convert': 'USD'}")
        return String(response.body)
    catch e
        return "Error occurred : $e"
    end
end

response = make_API_call(URL)
println(response)

```
