skip to Main Content

Im using Facebook API, trying to create a custom

async function createAudience(data) {
  try {
    console.log(` Upload: ${JSON.stringify(data)}`);
    return await axios.post(`https://example.com/{account_id}/audience`, data);
  } catch (error) {
    console.error(error);
  }
}

And it works just fine, but I need to access the response.status outside the function, and im lost…

      const ca_response = await createAudience(audienceData)
  .then((result) => {
    return result.status })
  .catch(err => console.error(err));

I can push it and it works, I can acces ((result) => { return result.status }) from the function without an issue, but can’t work with it from ouside… How can i create the const audienceStatus to be used on the rest of my code?? Thanks!

2

Answers


  1. Just create a variable outside of your function and store the result.status inside of it instead of returning it, like myVar = result.status

    Login or Signup to reply.
  2. you can do this:

    const ca_response = await createAudience(audienceData);
    console.log('audienceStatus', ca_response.status );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search