# For development purposes, how can I call my local web api from auth0 rule

**URL:** <https://community.auth0.com/t/for-development-purposes-how-can-i-call-my-local-web-api-from-auth0-rule/56168>\
**Category:** Get Help\
**Tags:** development, auth0-rules\
**Created:** [January 13, 2021, 8:31pm UTC](https://community.auth0.com/t/for-development-purposes-how-can-i-call-my-local-web-api-from-auth0-rule/56168 "2021-01-13T20:31:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![tdesai](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/tdesai/32/15525_2.png) [@tdesai](https://community.auth0.com/u/tdesai)\
**Post date:** [January 13, 2021, 8:31pm UTC](https://community.auth0.com/t/for-development-purposes-how-can-i-call-my-local-web-api-from-auth0-rule/56168/1 "2021-01-13T20:31:19Z")

</div>

For development purposes, I want to call my local web api from auth0 rule. The error I get is (pulled from rules logs) -  
Error: getaddrinfo ENOTFOUND [my-web-api-1.com](http://my-web-api-1.com)  
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:66:26) {  
errno: ‘ENOTFOUND’,  
code: ‘ENOTFOUND’,

My api has been configured for authentication in auth0. I get the access token and use this token to make the api call.  
Here is my rule script -

```auto
function (user, context, callback) {
  const axios = require('axios');
  //Request the access token
  const options = { method: 'POST',
    url: `https://${auth0.domain}/oauth/token`,
    headers: { 'content-type': 'application/json' },
    data: `{"client_id":"${configuration.RULE_APP_CLIENT_ID}","client_secret":"${configuration.RULE_APP_CLIENT_SECRET}","audience":"https://my-web-api-1.com","grant_type":"client_credentials"}` };
  axios(options)
    .then( res => {
      const access_token = res.data.access_token;
      const apiCallOpts = { method: 'GET',
                            url: 'https://my-web-api-1.com/<path>',
                            headers: { authorization: `Bearer ${access_token}`}
                          };
      axios(apiCallOpts).then(apiRes => {
        console.log(apiRes);
      }).catch( err => {
      		console.log(err);
    	});
    return callback(null, user, context);
    })
    .catch( err => {
      console.log(err);
    });  
}

```

 ![image](https://global.discourse-cdn.com/auth0/original/3X/5/5/55a049b2d80a9faea61e97b3443c983fa7db2c2a.jpeg)

NOTE: In my dev environment (windows 10) I did create inbound rules for the IP addresses mentioned here [Auth0 IP Addresses for Allow Lists](https://auth0.com/docs/security/allowlist-ip-addresses) for US region.

---

<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:** [January 13, 2021, 11:15pm UTC](https://community.auth0.com/t/for-development-purposes-how-can-i-call-my-local-web-api-from-auth0-rule/56168/2 "2021-01-13T23:15:20Z")

</div>

It looks like this error is stating that the URL provided cannot be resolved, or doesn’t exist.

`https://my-web-api-1.com`

---

<div class="post-metadata">

**Author:** ![tdesai](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/tdesai/32/15525_2.png) [@tdesai](https://community.auth0.com/u/tdesai)\
**Post date:** [January 13, 2021, 11:23pm UTC](https://community.auth0.com/t/for-development-purposes-how-can-i-call-my-local-web-api-from-auth0-rule/56168/3 "2021-01-13T23:23:02Z")

</div>

Thank you for your reply. I have created the entry in my host file as follows -

127.0.0.1 [my-web-api-1.com](http://my-web-api-1.com)

Is this approach valid for development purposes? Or do I have to publish my api to a publically accessible url?

---

<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:** [January 13, 2021, 11:28pm UTC](https://community.auth0.com/t/for-development-purposes-how-can-i-call-my-local-web-api-from-auth0-rule/56168/5 "2021-01-13T23:28:49Z")

</div>

The rule is running in a container in the cloud, so yes, it needs to accessible from there. The host file is like a static DNS for your machine IIRC.

---

<div class="post-metadata">

**Author:** ![tdesai](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/tdesai/32/15525_2.png) [@tdesai](https://community.auth0.com/u/tdesai)\
**Post date:** [January 13, 2021, 11:42pm UTC](https://community.auth0.com/t/for-development-purposes-how-can-i-call-my-local-web-api-from-auth0-rule/56168/6 "2021-01-13T23:42:22Z")

</div>

Sounds good! Thank you Dan!

---

<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:** [January 14, 2021, 8:12pm UTC](https://community.auth0.com/t/for-development-purposes-how-can-i-call-my-local-web-api-from-auth0-rule/56168/7 "2021-01-14T20:12:38Z")

</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:** [February 12, 2021, 6:20pm UTC](https://community.auth0.com/t/for-development-purposes-how-can-i-call-my-local-web-api-from-auth0-rule/56168/8 "2021-02-12T18:20:37Z")

</div>

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