# Auth0 giving 403 'Forbidden' while calling external API in actions

**URL:** <https://community.auth0.com/t/auth0-giving-403-forbidden-while-calling-external-api-in-actions/133328>\
**Category:** Get Help\
**Tags:** apis, application\
**Created:** [May 3, 2024, 11:50am UTC](https://community.auth0.com/t/auth0-giving-403-forbidden-while-calling-external-api-in-actions/133328 "2024-05-03T11:50:44Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![ayush.oli](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ayush.oli/32/56197_2.png) [@ayush.oli](https://community.auth0.com/u/ayush.oli)\
**Post date:** [May 3, 2024, 11:50am UTC](https://community.auth0.com/t/auth0-giving-403-forbidden-while-calling-external-api-in-actions/133328/1 "2024-05-03T11:50:44Z")

</div>

While I am calling my backend API in pre-registration Hook it’s giving me error saying 403 ‘Forbidden’. This suddenly happened and it was working before.

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [May 3, 2024, 9:10pm UTC](https://community.auth0.com/t/auth0-giving-403-forbidden-while-calling-external-api-in-actions/133328/3 "2024-05-03T21:10:59Z")

</div>

Hi @ayush.oli,

Welcome to the Auth0 Community!

Could you try using the Actions interface to test your Action script and see what might be causing the 403 Forbidden error?

Keep me posted on what you find.

---

<div class="post-metadata">

**Author:** ![ayush.oli](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ayush.oli/32/56197_2.png) [@ayush.oli](https://community.auth0.com/u/ayush.oli)\
**Post date:** [May 6, 2024, 9:34am UTC](https://community.auth0.com/t/auth0-giving-403-forbidden-while-calling-external-api-in-actions/133328/4 "2024-05-06T09:34:08Z")

</div>

Yes, the API I am calling in pre-registration action is the backend api and it was working fine but all of a sudden the API gives me forbidden error.  
{  
status: 403,  
statusText: ‘Forbidden’,  
}.  
The API is working fine in other places tho.

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [May 8, 2024, 6:52pm UTC](https://community.auth0.com/t/auth0-giving-403-forbidden-while-calling-external-api-in-actions/133328/5 "2024-05-08T18:52:50Z")

</div>

Hi @ayush.oli,

Could you share your action script with me? Please be sure to obfuscate any sensitive information.

Thanks,  
Rueben

---

<div class="post-metadata">

**Author:** ![ayush.oli](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ayush.oli/32/56197_2.png) [@ayush.oli](https://community.auth0.com/u/ayush.oli)\
**Post date:** [May 9, 2024, 11:42am UTC](https://community.auth0.com/t/auth0-giving-403-forbidden-while-calling-external-api-in-actions/133328/6 "2024-05-09T11:42:23Z")

</div>

Hey @rueben.tiow,

This is the action script.

```auto
const axios = require('axios');
exports.onExecutePreUserRegistration = async (event, api) => {
    try {
    const options = {
      headers: {
        'Content-Type': 'application/json'
      }
    };

    const { email, user_metadata } = event.user;
    const payload = {
      "phoneNumber": user_metadata.phone_number,
      "email": email,
      'lastName': user_metadata.last_name,
      'name':user_metadata.first_name + " " + user_metadata.last_name,
      "accountCategoryId": user_metadata.account_category,
      "accountTypeId": user_metadata.account_type,
    }

    const response = await axios.post(event.secrets.API_ENDPOINT, payload, options);
    console.log("response", response);
    if(response.data.msg === "Duplicate phone") {
        api.access.deny('duplicate_phone', "Invalid Phone Number");
    }
    if(response.data.msg === "Duplicate email") {
        api.access.deny('duplicate_email', "Invalid Email");
    }
    if(response.data.msg === "Customer successfully created" && response.data.data.azureCustomerId && response.data.data.shopifyId) {
      api.user.setUserMetadata('azureCustomerId', response.data.data.azureCustomerId);
      api.user.setUserMetadata('shopifyId', response.data.data.shopifyId);
    }
    } catch(error) {
      // @ts-ignore
      console.log("Error", error.response.data);
      // @ts-ignore
      if(error.response.data.errors[0] === "Enteravalidphonenumber") {
        api.access.deny('invalid_phone_number', 'Invalid Phone Number');
      // @ts-ignore
      } else if(error.response.data.errors[0] === "Phonehasalreadybeentaken"){
        api.access.deny('duplicate_phone', "Invalid Phone Number");
      }
      api.access.deny('api_error', 'Error in API');
    }
};

```

---

<div class="post-metadata">

**Author:** ![ayush.oli](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ayush.oli/32/56197_2.png) [@ayush.oli](https://community.auth0.com/u/ayush.oli)\
**Post date:** [May 14, 2024, 8:28am UTC](https://community.auth0.com/t/auth0-giving-403-forbidden-while-calling-external-api-in-actions/133328/7 "2024-05-14T08:28:00Z")

</div>

Pinging again for this. We have been stuck for really long time.

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [May 14, 2024, 11:17pm UTC](https://community.auth0.com/t/auth0-giving-403-forbidden-while-calling-external-api-in-actions/133328/8 "2024-05-14T23:17:24Z")

</div>

Hi @ayush.oli,

I have reviewed your code snippet. Could you share what is the API endpoint you are trying to reach?

Is it an Auth0-related endpoint? Like one from the Management API?

Thanks,  
Rueben

---

<div class="post-metadata">

**Author:** ![KiteWinset](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/kitewinset/32/52953_2.png) [@KiteWinset](https://community.auth0.com/u/KiteWinset)\
**Post date:** [May 15, 2024, 10:38am UTC](https://community.auth0.com/t/auth0-giving-403-forbidden-while-calling-external-api-in-actions/133328/10 "2024-05-15T10:38:13Z")

</div>

> [@ayush.oli](#):
>
> While I am calling my backend API in pre-registration Hook it’s giving me error saying 403 ‘Forbidden’. This suddenly happened and it was working before. [LockSmith West Hollywood](https://www.bnolocksmithca.com)

Check if the API permissions or token scopes have changed. Also, ensure proper authentication and authorization in Auth0 Actions.

---

<div class="post-metadata">

**Author:** ![ayush.oli](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ayush.oli/32/56197_2.png) [@ayush.oli](https://community.auth0.com/u/ayush.oli)\
**Post date:** [May 15, 2024, 1:16pm UTC](https://community.auth0.com/t/auth0-giving-403-forbidden-while-calling-external-api-in-actions/133328/11 "2024-05-15T13:16:43Z")

</div>

This was something unrelated to auth0. We were having issues with Cloudflare. Closing this for now. Thank you for your help.

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [May 15, 2024, 6:44pm UTC](https://community.auth0.com/t/auth0-giving-403-forbidden-while-calling-external-api-in-actions/133328/12 "2024-05-15T18:44:38Z")

</div>

Hi @ayush.oli,

That sounds good.

Keep us posted if you continue to experience issues.

Thanks,  
Rueben

---

<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:** [May 29, 2024, 6:45pm UTC](https://community.auth0.com/t/auth0-giving-403-forbidden-while-calling-external-api-in-actions/133328/13 "2024-05-29T18:45:21Z")

</div>

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