# How do I call my API from an Action?

**URL:** <https://community.auth0.com/t/how-do-i-call-my-api-from-an-action/69041>\
**Category:** Get Help\
**Tags:** registration, api, auth0\
**Created:** [September 3, 2021, 4:54am UTC](https://community.auth0.com/t/how-do-i-call-my-api-from-an-action/69041 "2021-09-03T04:54:29Z")\
**Posts on this page:** 1\
**Showing post:** 7

<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 9, 2021, 9:24pm UTC](https://community.auth0.com/t/how-do-i-call-my-api-from-an-action/69041/7 "2021-09-09T21:24:00Z")

</div>

Hey @joshuarichards001,

I was able to create an action that works to request a token and call an endpoint with the token, while logging the data from each request.Can you take a look and see if this will work for you? Also, can you DM me the URL (`event.secrets.API_CREATE_USER`) you are trying to call?

Here is the action I created:

```auto
/**
* Handler that will be called during the execution of a PostUserRegistration flow.
*
* @param {Event} event - Details about the context and user that has registered.
*/
const axios = require('axios');

exports.onExecutePostUserRegistration = async (event) => {

  const tokenOptions = {
    method: 'POST',
    url: `https://${event.secrets.DOMAIN}/oauth/token`,
    headers: { 'content-type': 'application/json' },
    data: {
      grant_type: 'client_credentials',
      client_id: event.secrets.CLIENT_ID,
      client_secret: event.secrets.CLIENT_SECRET,
      audience: `https://${event.secrets.DOMAIN}/api/v2/`
    }
  };

  const res = await axios.request(tokenOptions);
  console.log('Access Token: ', res.data.access_token);
  
  const usersOptions = {
    method: 'GET',
    url: `https://${event.secrets.DOMAIN}/api/v2/users`,
    headers: {
      'Authorization': `Bearer ${res.data.access_token}`,
      'content-type': 'application/json'
    }
  };

  const users = await axios.request(usersOptions);
  console.log('Users: ', users.data);
};

```

---

_[View the full topic](https://community.auth0.com/t/how-do-i-call-my-api-from-an-action/69041)._
