# Is it possible to use async/await in rules or some similar construct?

**URL:** <https://community.auth0.com/t/is-it-possible-to-use-async-await-in-rules-or-some-similar-construct/49821>\
**Category:** Get Help\
**Tags:** rules, auth0\
**Created:** [September 16, 2020, 6:25am UTC](https://community.auth0.com/t/is-it-possible-to-use-async-await-in-rules-or-some-similar-construct/49821 "2020-09-16T06:25:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![roland.eriksson](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/roland.eriksson/32/12835_2.png) [@roland.eriksson](https://community.auth0.com/u/roland.eriksson)\
**Post date:** [September 16, 2020, 6:25am UTC](https://community.auth0.com/t/is-it-possible-to-use-async-await-in-rules-or-some-similar-construct/49821/1 "2020-09-16T06:25:57Z")

</div>

Hi.

I have created a rule that assigns roles based on users ad groups connected in azure ad.  
The rule first delete all roles for the user and then assigns new roles based on the mapped ad group data.  
I use “request” to call the auth0 management api for the delete and assignment.  
My problem is that the calls executes async so somtimes the delete comes after the assignment.  
Is it possible to get it synchronously?  
If so, can you please show an example.

Best regards Roland

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [September 18, 2020, 6:59pm UTC](https://community.auth0.com/t/is-it-possible-to-use-async-await-in-rules-or-some-similar-construct/49821/3 "2020-09-18T18:59:47Z")

</div>

Hi @roland.eriksson,

Yes, you shouldn’t have a problem with that.

I use axios because the request library is deprecated. Here is an example:

```auto
function (user, context, callback) {
  const axios = require('axios');
  
  const getEcho = async () => {
    try {
      const resultA = await axios.get('https://postman-echo.com/get?foo1=bar1');
      console.log(resultA.data);
      const resultB = await axios.get(`https://postman-echo.com/get?foo2=${resultA.data.args.foo1}`);
      console.log(resultB.data);
    } catch (error) {
      console.error(error);
    }
  };

  getEcho();
  return callback(null, user, context);
}

```

---

<div class="post-metadata">

**Author:** ![roland.eriksson](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/roland.eriksson/32/12835_2.png) [@roland.eriksson](https://community.auth0.com/u/roland.eriksson)\
**Post date:** [September 22, 2020, 6:45am UTC](https://community.auth0.com/t/is-it-possible-to-use-async-await-in-rules-or-some-similar-construct/49821/4 "2020-09-22T06:45:49Z")

</div>

Thank you very much. Works as a charm.

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [September 22, 2020, 3:27pm UTC](https://community.auth0.com/t/is-it-possible-to-use-async-await-in-rules-or-some-similar-construct/49821/5 "2020-09-22T15:27:46Z")

</div>

No problem. Let us know if you have any other questions!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [October 7, 2020, 3:27pm UTC](https://community.auth0.com/t/is-it-possible-to-use-async-await-in-rules-or-some-similar-construct/49821/6 "2020-10-07T15:27:58Z")

</div>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
