# Make a POST to API server using accessToken, after a user has registered

**URL:** <https://community.auth0.com/t/make-a-post-to-api-server-using-accesstoken-after-a-user-has-registered/15918>\
**Category:** Get Help\
**Created:** [September 26, 2018, 5:04am UTC](https://community.auth0.com/t/make-a-post-to-api-server-using-accesstoken-after-a-user-has-registered/15918 "2018-09-26T05:04:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dominic\_Bou-Samra](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dominic_bou-samra/32/7008_2.png) [@Dominic\_Bou-Samra](https://community.auth0.com/u/Dominic_Bou-Samra)\
**Post date:** [September 26, 2018, 5:04am UTC](https://community.auth0.com/t/make-a-post-to-api-server-using-accesstoken-after-a-user-has-registered/15918/1 "2018-09-26T05:04:59Z")

</div>

I want to create a resource for the user when they first register. In order to do that I need the access token, of the newly created and logged in user.

I tried using Rules, **but the accessToken is equal to an empty object after logging in** for some reason.

```
function (user, context, callback) {
  console.log(user);
  console.log(context);
  
  if (context.stats.loginsCount === 1) {
    console.log("Creating example resource");
    
    const options = {
      method: 'POST',
      uri: "http://",
      headers: {
        "Authorization": "Bearer " + context.accessToken
      }
    };
    request(options, function(err, res) {
      console.log(res.body);
    });   
  }

  callback(null, user, context);
}

```

How do I send a POST after the user has logged in?

---

<div class="post-metadata">

**Author:** ![philip.r.thompson](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/philip.r.thompson/32/12911_2.png) [@philip.r.thompson](https://community.auth0.com/u/philip.r.thompson)\
**Post date:** [March 22, 2019, 4:33am UTC](https://community.auth0.com/t/make-a-post-to-api-server-using-accesstoken-after-a-user-has-registered/15918/2 "2019-03-22T04:33:51Z")

</div>

Did you ever happen to resolve this? I just opened a similar issue…

> [@Add new user to own API from rule](http://community.auth0.com/t/add-new-user-to-own-api-from-rule/22971):
>
> I’m a bit stuck after lots of reading and trying. Once a user registers with Auth0 and logs in for the first time, I’d like to run a rule that makes an API request to my application to create a new user. The problem is that I need a valid JWT access token to hit my API. I thought that the access token and/or id token that the user receives once authenticating in my react app (and is subsequently used to make api requests) would be available in the rules… but it doesn’t appear to be. Is the ac…

Thanks.

---

<div class="post-metadata">

**Author:** ![dak2009](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dak2009/32/44901_2.png) [@dak2009](https://community.auth0.com/u/dak2009)\
**Post date:** [June 18, 2019, 1:21pm UTC](https://community.auth0.com/t/make-a-post-to-api-server-using-accesstoken-after-a-user-has-registered/15918/3 "2019-06-18T13:21:32Z")

</div>

Did you guys ever get this to work? I’m stuck being unable to get an accessToken.

> [@Running a rule to call an API does not work due to 401 error](http://community.auth0.com/t/running-a-rule-to-call-an-api-does-not-work-due-to-401-error/26711):
>
> I have written a rule that posts a new user to my API. The rule fires when I sign up a new user. My API refuses the POST with a 401 error. When I debug the rule, the context.accessToken is empty {}. How do I get an access token to pass to my API? I can’t make heads or tails of the rule documentation. function (user, context, callback) { if (context.stats.loginsCount === 1) { return callback(null, user, context); } const request = require('request'); const payload = \_.extend({…

---

<div class="post-metadata">

**Author:** ![mvkv](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/mvkv/32/28413_2.png) [@mvkv](https://community.auth0.com/u/mvkv)\
**Post date:** [March 26, 2021, 9:14pm UTC](https://community.auth0.com/t/make-a-post-to-api-server-using-accesstoken-after-a-user-has-registered/15918/4 "2021-03-26T21:14:42Z")

</div>

Hi there! 2020, still having this issue… Someone had managed to resolve it?
