fbsamples/messenger-platform-samples

Webhook post error

Closed this issue ยท 9 comments

Hi, I did everything as instructions(https://developers.facebook.com/docs/messenger-platform/getting-started/webhook-setup) but I keep getting this error!
What did I do wrong?

Requesting side>>>

curl -H "Content-Type:application/json" -X POST "localhost:1337/webhook" -d '{"object": "page", "entry": [{"messaging": [{"message": "TEST_MESSAGE"}]}]}'

<title>Error</title>
SyntaxError: Unexpected token # in JSON at position 0
   at JSON.parse (<anonymous>)
   at createStrictSyntaxError (C:\Users\yshvc\messenger-webhook\node_modules\body-parser\lib\types\json.js:157:10)
   at parse (C:\Users\yshvc\messenger-webhook\node_modules\body-parser\lib\types\json.js:83:15)
   at C:\Users\yshvc\messenger-webhook\node_modules\body-parser\lib\read.js:121:18
   at invokeCallback (C:\Users\yshvc\messenger-webhook\node_modules\raw-body\index.js:224:16)
   at done (C:\Users\yshvc\messenger-webhook\node_modules\raw-body\index.js:213:7)
   at IncomingMessage.onEnd (C:\Users\yshvc\messenger-webhook\node_modules\raw-body\index.js:273:7)
   at emitNone (events.js:106:13)
   at IncomingMessage.emit (events.js:208:7)
   at endReadableNT (_stream_readable.js:1056:12)
curl: (6) Couldn't resolve host 'page,' curl: (6) Couldn't resolve host 'entry' curl: (3) [globbing] bad range specification in column 2 curl: (3) [globbing] bad range specification in column 2 curl: (3) [globbing] unmatched close brace/bracket in column 13

=====================================================

Node side>>>

SyntaxError: Unexpected token # in JSON at position 0
at JSON.parse ()
at createStrictSyntaxError (C:\Users\yshvc\messenger-webhook\node_modules\body-parser\lib\types\json.js:157:10)
at parse (C:\Users\yshvc\messenger-webhook\node_modules\body-parser\lib\types\json.js:83:15)
at C:\Users\yshvc\messenger-webhook\node_modules\body-parser\lib\read.js:121:18
at invokeCallback (C:\Users\yshvc\messenger-webhook\node_modules\raw-body\index.js:224:16)
at done (C:\Users\yshvc\messenger-webhook\node_modules\raw-body\index.js:213:7)
at IncomingMessage.onEnd (C:\Users\yshvc\messenger-webhook\node_modules\raw-body\index.js:273:7)
at emitNone (events.js:106:13)
at IncomingMessage.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1056:12)

Can you post a gist or link to your code? It appears you probably have a syntax error in your index.js file.

https://gist.github.com/samko635/223521633a4a317c2a5bc4c6f110d376
These are the files I created following the manual. And there is node_modules directory created by Node.js promt with "npm install express body-parser" command. I'll add exrpess vers. for ref.

  • body-parser@1.18.2
  • express@4.16.2

What am I doing wrong? Json seems fine to me and I even checked it with https://jsonlint.com/

What version of node are you running? I've run the code and the cURL request you provided and did not get an error.

Closing this since there has been no response for over a week.

I'm also getting this issue! Please help!

also getting same error. any chance to reopen?

I am using curl on cmder and this command works fine:
curl -H "Content-Type: application/json" -X POST "localhost:1337/webhook" -d {\"object\":\"page\",\"entry\":[{\"messaging\":[{\"message\":\"TEST_MESSAGE\"}]}]}

I've been having the exact same problem, i tried on the command line tool, but i still can't figure out what the problem is.

I was just having the same error and tried to use the version of @vojtob it started worked!
Magic