Stack Overflow / API Gateway - Body Mapping Template - optional body parameters
Stack Overflow / API Gateway - Body Mapping Template - optional body parameters
I have a POST API Gateway method to which I am sending the following application/json body in order to pass parameters from it to a Lambda that the method is connected to:
{
"otherClientId": "12345",
"message": "Text",
"seconds": 0,
"hours": 0
}
I am using the following mapping template:
#set($inputRoot = $input.path('$'))
{
"authorizedUser": "$context.authorizer.principalId",
"otherClientId": "$inputRoot.otherClientId",
"message": "$inputRoot.message",
"amount": $inputRoot.amount,
"duration": $inputRoot.duration
}
The problem I am experiencing is that I receive a "Bad String" error when attempting to send the request without amount or duration. For some reason these parameters do not seem to be optional (but I need them to be!). I am able to miss out other parameters, like message for instance, but not the two number parameters.
Has anybody else experienced this or can somebody point out the obvious that I am probably missing? The AWS documentation is a little sparse on the subject.