# Getting 401 in my auth0 action, even though the token works in postman?

**URL:** <https://community.auth0.com/t/getting-401-in-my-auth0-action-even-though-the-token-works-in-postman/100876>\
**Category:** Get Help\
**Tags:** apis, application\
**Created:** [February 20, 2023, 6:19pm UTC](https://community.auth0.com/t/getting-401-in-my-auth0-action-even-though-the-token-works-in-postman/100876 "2023-02-20T18:19:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nolanl13](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nolanl13/32/42929_2.png) [@nolanl13](https://community.auth0.com/u/nolanl13)\
**Post date:** [February 20, 2023, 6:19pm UTC](https://community.auth0.com/t/getting-401-in-my-auth0-action-even-though-the-token-works-in-postman/100876/1 "2023-02-20T18:19:27Z")

</div>

Hello, so i am completely stumped on this one. I created an action last Friday to ping my API on post user registration. It worked fine on Friday and today I had a new error about a callback issue. I changed stuff around and it now seems to run but it gets a 401 when I try to ping the API. Ive tried doing a cURL with the same client id and secret as the M2M one I created for the action. and it works fine no auth errors. but for some reason it doesn’t when its running in the action? It’s also working when I test the action and a valid access token is created? I’m baffled, any help on this would really be amazing.

this is my code

```auto

const axios = require('axios');
exports.onExecutePostUserRegistration = async (event, api) => {
console.log(event.user)
   const options = { method: 'POST',
    url: `https://project-pylo.eu.auth0.com/oauth/token`,
    headers: { 'content-type': 'application/json' },
    data: `{"client_id":"${event.secrets.RULE_APP_CLIENT_ID}","client_secret":"${event.secrets.RULE_APP_CLIENT_SECRET}","audience":"https://project-pylo-api.com","grant_type":"client_credentials"}` };
  
  axios(options)
    .then((response) => {
      const access_token = response.data.access_token;
     const createUserResponse = axios.post("https://eaa6-178-167-195-2.eu.ngrok.io/user", { 
  name: event.user.name,
  email: event.user.email,
  sub: event.user.user_id
}, 
{
  headers: {
    Authorization: `Bearer ${access_token}`
  }
      });
      console.log(createUserResponse.data);
    })
    .catch((error) => {
      console.error(error);
    });

};

```

---

<div class="post-metadata">

**Author:** ![spoudel](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/spoudel/32/51376_2.png) [@spoudel](https://community.auth0.com/u/spoudel)\
**Post date:** [February 20, 2023, 8:12pm UTC](https://community.auth0.com/t/getting-401-in-my-auth0-action-even-though-the-token-works-in-postman/100876/2 "2023-02-20T20:12:41Z")

</div>

Is this client authorized to use the api that you’re trying to call. And, does the client have the appropriate scopes. I would look into it first. The logs might be helpful too.

---

<div class="post-metadata">

**Author:** ![nolanl13](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nolanl13/32/42929_2.png) [@nolanl13](https://community.auth0.com/u/nolanl13)\
**Post date:** [February 23, 2023, 10:33am UTC](https://community.auth0.com/t/getting-401-in-my-auth0-action-even-though-the-token-works-in-postman/100876/3 "2023-02-23T10:33:40Z")

</div>

Hi thanks for replying to my post!  
Yes it does have authorisation and the appropriate scopes, read:users, write:users, I moved it over to a after first login action as from some digging I saw that post-registration seems to only be triggered on creation in a customer database linked to auth0 or passwordless registration which is not what I’m using. When I run the test in the action I can see a user is created and the user payload prints out in my API console so it has permissions in testing just not when I actually sign someone up?

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [February 24, 2023, 12:23am UTC](https://community.auth0.com/t/getting-401-in-my-auth0-action-even-though-the-token-works-in-postman/100876/5 "2023-02-24T00:23:05Z")

</div>

Hey there @nolanl13 !

> [@nolanl13](#):
>
> I moved it over to a after first login action as from some digging I saw that post-registration seems to only be triggered on creation in a customer database linked to auth0 or passwordless registration which is not what I’m using.

That’s correct that post registration Action will only run for database users, i.e. not a social connection. See (and upvote!) this feedback request:

> [@Trigger the Pre User Registration flow for social and other non-database connection types](https://community.auth0.com/t/trigger-the-pre-user-registration-flow-for-social-and-other-non-database-connection-types/81070):
>
> Feature: Provide a short title of your feature request/feedback. Trigger the Pre User Registration flow for social and other non-database connection types. Description: Give us some details about your feedback/feature request. Examples, screenshots, videos, etc. are helpful. For some reason, the Pre User Registration flow does not run for social or other non-database connection types. This makes it impossible to: Create a corresponding user in an external database, before the user is regist…

Is the code successful in a post login Action?

---

<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:** [March 10, 2023, 12:23am UTC](https://community.auth0.com/t/getting-401-in-my-auth0-action-even-though-the-token-works-in-postman/100876/6 "2023-03-10T00:23:45Z")

</div>

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