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

146
Vistas
How to map a result in a promise that comes from a function call

I have this function that returns a result from a GET in an API (I am using an AWS Rest API, for contextualization):

const listUsers = async () => {
  const apiName = 'AdminQueries'
  const path = '/listUsers'
  const params = {
    headers: {
      'Content-Type': 'application/json',
      Authorization: `${(await Auth.currentSession())
        .getAccessToken()
        .getJwtToken()}`,
    },
  }
  return await API.get(apiName, path, params)
}

And if i call the function to print on console, like:

console.log(listUsers())

I get an array on my console:

Promise {<pending>}
__proto__: Promise
[[PromiseState]]: "fulfilled"
[[PromiseResult]]: Object
Users: Array(42)
0: {Username: "00e534e3-08ee-4bc1-9d19-ab18208e3f94", Attributes: Array(5), UserCreateDate: "2021-09-06T10:05:35.537Z", UserLastModifiedDate: "2021-09-06T10:05:35.537Z", Enabled: true, …}
1: {Username: "05f4ce2e-4b57-48d5-9f5f-e18d250aefb4", Attributes: Array(6), UserCreateDate: "2021-09-10T19:45:32.002Z", UserLastModifiedDate: "2021-09-10T19:54:37.333Z", Enabled: true, …}
2: {Username: "06a78cc7-af6a-4fb6-975d-458c089b69a5", Attributes: Array(6), UserCreateDate: "2021-09-10T18:04:27.780Z", UserLastModifiedDate: "2021-09-10T18:04:27.780Z", Enabled: true, …}
3: {Username: "32652d77-e7a4-444a-9995-f8f50eb14633", Attributes: Array(6), UserCreateDate: "2021-09-06T15:48:24.897Z", UserLastModifiedDate: "2021-09-06T15:49:39.476Z", Enabled: true, …}
length: 42
__proto__: Array(0)
__proto__: Object

How do i map these users to show in an array? I tried but couldn't.

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

0

Your listUsers function is returning a promise. To get the response you can make use of something like this

const listUsers = async () => {
  const apiName = 'AdminQueries'
  const path = '/listUsers'
  const params = {
    headers: {
      'Content-Type': 'application/json',
      Authorization: `${(await Auth.currentSession())
        .getAccessToken()
        .getJwtToken()}`,
    },
  }
  return await API.get(apiName, path, params)
}

**** update ****
const func = async () => {
   const response = await listUsers();
   console.log(response);
}

func();
about 4 years ago · Juan Pablo Isaza Denunciar

0

const listUsers = async () => {
      const apiName = 'AdminQueries'
      const path = '/listUsers'
      const params = {
        headers: {
          'Content-Type': 'application/json',
          Authorization: `${(await Auth.currentSession())
            .getAccessToken()
            .getJwtToken()}`,
        },
      }
      return await API.get(apiName, path, params)
    }

    const func = async () => {
      const response = await listUsers();
      reponse.data?.map((item) => {
        console.log(item);
      })
    }
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