# Problem when calling custom endpoint from pre-registration hook

**URL:** <https://community.auth0.com/t/problem-when-calling-custom-endpoint-from-pre-registration-hook/8365>\
**Category:** Get Help\
**Tags:** hooks\
**Created:** [October 2, 2017, 10:24pm UTC](https://community.auth0.com/t/problem-when-calling-custom-endpoint-from-pre-registration-hook/8365 "2017-10-02T22:24:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![laxmikantanayak415](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/laxmikantanayak415/32/3572_2.png) [@laxmikantanayak415](https://community.auth0.com/u/laxmikantanayak415)\
**Post date:** [October 2, 2017, 10:24pm UTC](https://community.auth0.com/t/problem-when-calling-custom-endpoint-from-pre-registration-hook/8365/1 "2017-10-02T22:24:59Z")

</div>

I’m trying to do an HTTP call from Auth0 to my REST endpoint to save user in my db in pre-registration hook. However, it’s giving an 500 error which I am not able to understand:

```
request = require("request");

var options = {
 method: 'POST',
 url: 'http://domainname.com/users/create',
 headers: { 'Content-Type': 'application/json' },
 body: {
     "username": user.email,
     "password": user.password ,
     "api_account_id":user.user_metadata'api_account_id'],
     "organization":user.user_metadata'organization']
 }
};

request(options, function (error, response, body) {
 if (error) throw new Error(error);

 console.log(body);
});

```

---

<div class="post-metadata">

**Author:** ![jmangelo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jmangelo/32/7923_2.png) [@jmangelo](https://community.auth0.com/u/jmangelo)\
**Post date:** [October 3, 2017, 7:50pm UTC](https://community.auth0.com/t/problem-when-calling-custom-endpoint-from-pre-registration-hook/8365/2 "2017-10-03T19:50:54Z")

</div>

The information provided is not sufficient to provide a definitive answer (for example, you did not include full details about the error). However, based on the code provided and the fact that a pre-registration hook expects the following logic:

```
module.exports = function (user, context, cb) {
  var response = {};
  // ... logic here to calculate response
  cb(null, response);
};

```

There is at least one problematic situation with the code you showed; **you’re not calling the callback `cb` function to signal that your logic has completed**.

In particular, it should be something like (notice the call to `cb` both for error situations and successful completion of the hook’s logic):

```
// ...
request(options, function (error, response, body) {
  if (error) cb(new Error(error));

  console.log(body);

  cb(null, response); // assuming there's a response variable
});

```

---

<div class="post-metadata">

**Author:** ![laxmikantanayak415](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/laxmikantanayak415/32/3572_2.png) [@laxmikantanayak415](https://community.auth0.com/u/laxmikantanayak415)\
**Post date:** [October 3, 2017, 7:57pm UTC](https://community.auth0.com/t/problem-when-calling-custom-endpoint-from-pre-registration-hook/8365/3 "2017-10-03T19:57:57Z")

</div>

Actually i wanted to know , how can i call my rest api end point in preregistration hook in auth 0.

---

<div class="post-metadata">

**Author:** ![laxmikantanayak415](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/laxmikantanayak415/32/3572_2.png) [@laxmikantanayak415](https://community.auth0.com/u/laxmikantanayak415)\
**Post date:** [October 3, 2017, 7:57pm UTC](https://community.auth0.com/t/problem-when-calling-custom-endpoint-from-pre-registration-hook/8365/4 "2017-10-03T19:57:57Z")

</div>

Actually i wanted to know , how can i call my rest api end point in preregistration hook in auth 0.

---

<div class="post-metadata">

**Author:** ![jmangelo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jmangelo/32/7923_2.png) [@jmangelo](https://community.auth0.com/u/jmangelo)\
**Post date:** [October 16, 2017, 11:36pm UTC](https://community.auth0.com/t/problem-when-calling-custom-endpoint-from-pre-registration-hook/8365/5 "2017-10-16T23:36:58Z")

</div>

You can call it like in the sample code I included in the answer. The key point is that you need to call the hook callback in any code path possible after receiving the response.

---

<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 2, 2018, 5:56am UTC](https://community.auth0.com/t/problem-when-calling-custom-endpoint-from-pre-registration-hook/8365/6 "2018-03-02T05:56:47Z")

</div>


