Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

168
Views
How do I fetch more than one ID in an API endpoint that only supports one ID per request?

I'm using Coingecko API for price data and time (Unix) to output this in a chart, but the endpoint I'm using only supports one ID per request.

document.onreadystatechange = async () => {
  if (document.readyState === "complete") {
    const coin = "bitcoin";
    const currency = "brl";




const response = await fetch(

  `https://api.coingecko.com/api/v3/coins/${coin}/market_chart?vs_currency=${currency}&days=10&interval=hourly
  `
);

const data = await response.json();



const prices = data.prices.map((e) => e[1]);
const date = data.prices.map(i => i[0]);

i need that the function do the same also for solana, cardano, ripple, dash and litecoin

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If your API only supports one ID per request, and you need multiple IDs, you're going to need to make multiple requests.

One way to do them in parallel and wait for all to complete before continuing would be

const data = await Promise.all([
    fetch(endpoint1).then(response => response.json()), 
    fetch(endpoint2).then(response => response.json()), 
    fetch(endpoint3).then(response => response.json())
]);

The above will result in data containing an array of the responses for each endpoint -- data[0] will be the json from endpoint1, data[1] from endpoint2, and so forth. You'll need to step through them to get your prices and dates for each of the IDs (obviously it wouldn't make sense for the Promise.all() to try merging all the responses into one, because you'd have no way of knowing which price went with which ID.)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!