# Hitting AWS API Gateway endpoint in Hook getting error in response

**URL:** <https://community.auth0.com/t/hitting-aws-api-gateway-endpoint-in-hook-getting-error-in-response/14579>\
**Category:** Get Help\
**Tags:** aws, lambda, hooks, auth0\
**Created:** [August 22, 2018, 7:48pm UTC](https://community.auth0.com/t/hitting-aws-api-gateway-endpoint-in-hook-getting-error-in-response/14579 "2018-08-22T19:48:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gintomm](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/gintomm/32/8515_2.png) [@gintomm](https://community.auth0.com/u/gintomm)\
**Post date:** [August 22, 2018, 7:48pm UTC](https://community.auth0.com/t/hitting-aws-api-gateway-endpoint-in-hook-getting-error-in-response/14579/1 "2018-08-22T19:48:00Z")

</div>

Hi All,

I’m trying to setup a post registration hook, so once a user registers it hits a lambda function. The lambda function works fine as tested via the AWS console.

I’ve installed the `request` npm module so I can do a post request to the endpoint, but I keep on getting the following error returned.

`Unexpected string in JSON at position 33",`

I’ve looked around and found that I need to add my endpoint to the API dashboard but everytime I try I get a **Forbidden** message.

Any help would be greatly appreciated

---

<div class="post-metadata">

**Author:** ![Carlos\_Mostek](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/carlos_mostek/32/8140_2.png) [@Carlos\_Mostek](https://community.auth0.com/u/Carlos_Mostek)\
**Post date:** [August 22, 2018, 8:30pm UTC](https://community.auth0.com/t/hitting-aws-api-gateway-endpoint-in-hook-getting-error-in-response/14579/2 "2018-08-22T20:30:39Z")

</div>

Unexpected string in JSON is likely due to the JSON being returned not serialized correctly. It would be good to know where that error is being thrown. Are you parsing JSON as part of your response? Is that error coming from your lambda function? Someone somewhere is trying to parse JSON and whatever is given to it is not JSON. This often happens when you are requesting a content-type of JSON, but what is actually returned from the web service is not JSON (like an HTML error page or something like that).

Once you find where that is being thrown, you might want to print out what the JSON looks like and see if it is an HTML error or something like that that could give you a clue as to what the underlying error really is.

---

<div class="post-metadata">

**Author:** ![gintomm](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/gintomm/32/8515_2.png) [@gintomm](https://community.auth0.com/u/gintomm)\
**Post date:** [August 23, 2018, 8:12am UTC](https://community.auth0.com/t/hitting-aws-api-gateway-endpoint-in-hook-getting-error-in-response/14579/3 "2018-08-23T08:12:04Z")

</div>

Hi @Carlos_Mostek

thanks for a quick response. This is my code.

```auto
const request = require('request');
const apiURL = 'https://xxxxxxxx.execute-api.eu-west-2.amazonaws.com/xxxxxxx';

module.exports = function (user, context, cb) {
  request.post({
    url:apiURL, 
    json: { 
      "userId": user.id, 
      "userEmail": user.email,
      "userEmailVerified": user.emailVerified
    }
  }, (error, response, body) => { 
    cb(error, response);
  });
};

```

As you can see I’m posting a JSON via the request post and the error seems to be coming from Auth0 not my Lambda function as thats not even getting hit.

This is a more in depth error message from the Extend editor runner. The line its complaining about (40), doesn’t even exist so not sure what to make of it.

```auto
"SyntaxError: Unexpected string in JSON at position 40    
    at JSON.parse (<anonymous>)    
    at Object.internals.tryParseBuffer (/data/sandbox/node_modules/auth0-ext- 
    compilers/node_modules/wreck/lib/index.js:536:27)
    at finish (/data/sandbox/node_modules/auth0-ext-compilers/node_modules/wreck/lib/index.js:368:28)
    at wrapped (/data/sandbox/node_modules/auth0-ext-compilers/node_modules/hoek/lib/index.js:879:20)
    at module.exports.internals.Recorder.onReaderFinish (/data/sandbox/node_modules/auth0-ext- 
    compilers/node_modules/wreck/lib/index.js:415:16)
    at Object.onceWrapper (events.js:313:30)
    at emitNone (events.js:111:20)
    at module.exports.internals.Recorder.emit (events.js:208:7)
    at finishMaybe (_stream_writable.js:614:14)
    at afterWrite (_stream_writable.js:465:3)"
}
ln 26, col 16

```

Thanks

---

<div class="post-metadata">

**Author:** ![Carlos\_Mostek](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/carlos_mostek/32/8140_2.png) [@Carlos\_Mostek](https://community.auth0.com/u/Carlos_Mostek)\
**Post date:** [August 24, 2018, 5:07pm UTC](https://community.auth0.com/t/hitting-aws-api-gateway-endpoint-in-hook-getting-error-in-response/14579/4 "2018-08-24T17:07:15Z")

</div>

It isn’t line 40, it is character 40. If this is happening in the hook code, it would be good to be able to see the hook code.

If you install the realtime webtask log extension, then you can add some console.log’s to your hook to track down where you are running into issues in the hook. If you can isolate it down to an individual line, that would be good.

It seems like if you aren’t doing a JSON.parse directly, then what is probably happening is that it is calling some endpoint and the endpoint is not returning valid JSON. With console.logs, hopefully you can isolate down where that is happening.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [July 26, 2019, 9:33am UTC](https://community.auth0.com/t/hitting-aws-api-gateway-endpoint-in-hook-getting-error-in-response/14579/5 "2019-07-26T09:33:11Z")

</div>


