Executed code fails to call API on first try
# 🤝help
c
Hi,I have the following code which calls ASANA's API to get members of a team. When I refresh the bot and run it for the first time the array
workflow.team
is always empty. Bu the second time I run the Bot, the request runs successfully and the array is populated. Any Ideas what Im doing wrong? Thanks
Copy code
const getOptions = {
  method: 'GET',
  url: `https://app.asana.com/api/1.0/teams/${env.ASANA_MARKETING_GID}/team_memberships`,
  headers: {
    accept: 'application/json',
    authorization: `${env.ASANA_BARER_TOKEN}`
  }
};

axios.request(getOptions)
  .then((response) => {
    let team = [];
    if (response.status === 200) {
      const users = response.data.data;
      for (let i = 0, len = users.length; i < len; i++) {
        team.push(users[i].user);
      }
      console.log("team length", team.length)
      
      workflow.team = team
            
      }
}).catch((error) => {
    console.error(error);
  });
a
Hey @clean-branch-56468, my first instinct is that the flow isn't waiting for the API request to finish before moving on to the next card. Could you try making your API call using
await
?
c
Thanks @acceptable-kangaroo-64719 . That was going to be my next attempt. Does the order of the cards effect anything.
a
Yes! Cards are executed top-to-bottom
8 Views