2

when trying to post a WakeUp event with a JSON body to the Alexa events API using nodejs with axios or request-promise, the API always returns an error 500.

I posted to an online endpoint to actually see what gets posted and learned that the post body gets truncated which obviously results in invalid json. I abstracted the problem and tried to run it from a virgin nodejs installation by using repl.it and the result is the same.

Interestingly enough, there seems to be a relation between the length of the header and the body. So when I shorten the auth token in the header, more characters of the body get transferred. If I shorten the long tokens in the body to about 450 to 500 characters (it seems to vary) the whole request gets through. Obviously this is not a solution, because the tokens are needed for authentication.

When I experimented with the axios version used lowering it to 0.10 I once got a result but posting again lead to another 500. If I post often enough some requests get trough complete, even on the current axios version. I also tried using request-promise with the same outcome.

I got the feeling that I made a really stupid mistake but I can't find it and I really couldn't find anything on this topic, so it's driving me crazy. Any help would be greatly appreciated!

dnlmnn
  • 23
  • 5

2 Answers2

0

This looks like a tricky one.. first of all, I don't think you're making a really stupid mistake. It looks to me like one of the low-level modules doesn't like something in the POST body for some reason (really weird.).. I've played about with this and I'm getting exactly the same behaviour with both Axios and Request.. if I comment out the tokens (correlationToken and bearer token ) everything works fine.

If I test this locally, everything works as it should (e.g. set up express server and log POST body).

Also posting to https://postman-echo.com/post works as expected (with the original post data)..

I've created this here: https://repl.it/repls/YoungPuzzlingMonad

It looks to me like the original request to http://posthere.io is failing because of the request size only. If you try a very basic POST with a large JSON body you get the same result.

I get the same result with superagent too.. this leads me to believe this is something server side...

Terry Lennox
  • 29,471
  • 5
  • 28
  • 40
  • Thanks, so maybe using posthere.io led to a false positive. What's the result of using superagent? The same truncated body as posthere.io? – dnlmnn Mar 15 '19 at 20:45
  • Yeah I think so, it's just perplexing why this is happening! I tried with most of the http modules. – Terry Lennox Mar 15 '19 at 21:02
0

This was not related to the post request at all. The reason for the error after sending the WakeUp event was the missing configuration parameter containing the MACAdresses in the Alexa.WakeOnLANController interface. I used the AlexaResponse class to add the capability via createPayloadEndpointCapability which had not been modified to support the "new" WakeOnLANController interface yet.

It's a pity that the discovery was accepted and my WOL-capable device was added to my smart home devices although a required parameter was missing :(

posthere.io cutting off long post bodys cost me quite a few hours... On the upside, I go to know many different ways of issuing a post request in node ;)

Thanks again Terry for investigating!

dnlmnn
  • 23
  • 5