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

180
Views
Using returned async data

So I have an async function that goes like this:

async func1 (file, formData) {

    const id = await API.createCertificate(formData) // this returns the id of the newly created certificate

    const updatePayload = {
      id: id.data.data._id // mongo object id
      fileBuffer: file,
      type: 'certificate'
     }

    await API.attachFile(updatePayload) //attaches file to the newly created object

}

If I console log the id without making the payload it seems to display the right data

    async func1 (file, formData) {      
       const id = await API.createCertificate(formData) // this returns the id of the newly created certificate
       console.log('idContent',id) //this works and it displays all the right data      
    }

However, once I create the 'updatePayload' it throws an error at the id assignment saying cannot access 'data' which I don't get, await is supposed to wait for the promise to resolve before moving right? or am I missing something?

about 4 years ago · Juan Pablo Isaza
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!