coinmarketcap new api Node.js to php

I'm taking data from coinmarketcap.com using their API. This week they updated the api so now you need an api key to access the data. Now I need to add more details to the http call. In the API document they show this NodeJs code:

/* Example in Node.js ES6 using request-promise, concepts should translate to your language of choice */

const rp = require('request-promise');
const requestOptions = {
  method: 'GET',
  uri: 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest',
  qs: {
    start: 1,
    limit: 5000,
    convert: 'USD'
  headers: {
    'X-CMC_PRO_API_KEY': 'b54bcf4d-1bca-4e8e-9a24-22ff2c3d462c'
  json: true,
  gzip: true

rp(requestOptions).then(response => {
  console.log('API call response:', response);
}).catch((err) => {
  console.log('API call error:', err.message);

Can anyone help me convert the attached nodejs code to php?

- - Source


answered 1 week ago Mehrdad Zeus #1

In my opinion, converting their nodeJs code to PHP might be an unproductive task if you have been using PHP all along to work with Coinmarketcap's API.

I assume you have been using cURL to access their API before the update happened and API_KEY became needed for requests.

Simply add the following to your cURL request in PHP and replace API_SECRET with the api key you received from HERE:

curl_setopt($ch, CURLOPT_HTTPHEADER, array(

comments powered by Disqus