Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

180
Vistas
Getting an error trying to run rapidapi call using async and await

I keep getting the following error when I try to run a GET request from Rapid API

Uncaught (in promise) ReferenceError: Cannot access 'getData' before initialization

const RAPIDAPI_KEY =
  import.meta.env.VITE_RAPIDAPI_KEY;
const GEOLOCATION_URL = "https://ip-geo-location.p.rapidapi.com/ip/check?format=json";
const GEOLOCATION_HOST = "ip-geo-location.p.rapidapi.com";

const getData = async(url, host) => {
  const response = await fetch(url, {
    method: "GET",
    headers: {
      accept: "application/json",
      "x-rapidapi-host": host,
      "x-rapidapi-key": RAPIDAPI_KEY
    }
  })

  if (!response.ok) {
    throw new Error(`HTTP error! status: ${response.status}`)
  }

  return await response.json();
}

const runApiQueries = async() => {
  // GET CITY NAME
  const getData = await getData(GEOLOCATION_URL, GEOLOCATION_HOST);
  console.log(getData);
}

runApiQueries();

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The problem is the line

  const getData = await getData(GEOLOCATION_URL, GEOLOCATION_HOST);

it should've been

  const data = await getData(GEOLOCATION_URL, GEOLOCATION_HOST);

Under any circumstances, you shouldn't specify variable name the same as function or any other defined identifier.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda