Unable to push data via AWS API Gateway: Could not parse request body

Hi everyone,

I’m using AWS API Gateway + Lambda + DynamoDB for a small little project to record temperature data from a TMP102 sensor.

My Particle WebHook is throwing the following error message,

“Could not parse request body into json: Unrecognized token ‘event’: was expecting (‘true’, ‘false’ or ‘null’)\n at [Source: [B@64bac5c9; line: 1, column: 7]”

I’ve been Googling for a bit trying to figure out a solution, without any luck. I found some notes that it’s a Lambda issue, but haven’t been able to confirm anything.

Here’s the JSON that is being passed as the event:

{
“event”: “temperature”,
“data”: “25.187500”,
“published_at”: “2016-09-24T00:32:42.597Z”,
“coreid”: “XXXYYYZZZ”
}

I’m at a loss, anyone have any suggestions?

Thanks,

Brett

I’m not sure about what the problem is but I am sure that there are a few guys on here that are doing the same thing and have posted their code which shows how they are doing it. I would search for AWS Lambda and see if anything helpful comes up until somebody else chimes in.

@brettg98 I have the same stack AWS API GW -> Lambda -> DynamoDB

One thing I had to change was the default JSON sent by Particle.

Here’s what I have sent:

{
  "id": "{{PARTICLE_DEVICE_ID}}",
  "value": "{{PARTICLE_EVENT_VALUE}}",
  "event": "{{PARTICLE_EVENT_NAME}}"
}
1 Like

The problem is not the event you are using, the problem is the parse for the json. In APIGateway you have mapped the input to something like:

{
“string_param_1”: “$input.params(‘string_param_1’)”,
“string_param_2”: “$input.params(‘string_param_2’)”,
“integer_param_1”: $input.params(‘string_param_1’)
}

in case our input values are:

string_param_1: Hello
string_param_2: World
integer_param_1: 33

the transformation will be:

{
“string_param_1”: “Hello”,
“string_param_2”: “World”,
“integer_param_1”: 33
}

It’s a valid, JSON and you get no error. But, if your params are for example:

string_param_1: Hello
string_param_2: World
integer_param_1: !!

The output json will be:

{
“string_param_1”: “Hello”,
“string_param_2”: “World”,
“integer_param_1”: !!
}

As you can see, it’s not a valid json, so apigteway will return the error you are getting.

If you post your mapping on apigateway i can tell you exactly which param is the one screwing your parse.