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

163
Vistas
How do I return an item from an async funtion

Ive been looking into trying to get information from websites using fetch. Trying async/await was my first solution, and so far it has been going well. Getting the information I needed was a breeze, but trying to retrieve that data in main is my problem. Const data in my main function even with the await tag only returns an undefined object. How can I get the data that I have in the function into my main

import React from "react";
import {
  WASTEMANAGEMENT_USERNAME,
  WASTEMANAGEMENT_PASSWORD,
  WASTEMANAGEMENT_APIKEY_AUTH,
  WASTEMANAGEMENT_APIKEY_CUSTID,
  WASTEMANAGEMENT_APIKEY_DATA,
} from "@env";

async function login() {
  let response = await fetch("https://rest-api.wm.com/user/authenticate", {
    method: "POST",
    headers: {
      "content-type": "application/json",
      apikey: WASTEMANAGEMENT_APIKEY_AUTH,
    },
    body: JSON.stringify({
      username: WASTEMANAGEMENT_USERNAME,
      password: WASTEMANAGEMENT_PASSWORD,
      locale: "en_US",
    }),
  });
  let res = await response.json();

  const id = res.data.id;
  const access_token = res.data.access_token;

  response = await fetch(
    `https://rest-api.wm.com/authorize/user/${id}/accounts?lang=en_US`,
    {
      method: "GET",
      headers: {
        oktatoken: access_token,
        apikey: WASTEMANAGEMENT_APIKEY_CUSTID,
      },
    }
  );
  res = await response.json();

  const custId = res.data.linkedAccounts[0].custAccountId;

  response = await fetch(
    `https://rest-api.wm.com/account/${custId}/invoice?userId=${id}`,
    {
      method: "GET",
      headers: {
        apikey: WASTEMANAGEMENT_APIKEY_DATA,
        token: access_token,
      },
    }
  );
  res = await response.json();

  res.body.balances.filter((item) => {
    if (item.type === "Current") {
      console.log(item);
      return item;
    }
  });
}

const WasteManagementLogin = async () => {
  const data = await login();
  console.log(data);
};

export default WasteManagementLogin; 
about 4 years ago · Juan Pablo Isaza
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