Reputation: 8354
I am using API Gateway to build a patch method.
In then Integration Request - Mapping Template
i added:
{ "id": "$input.params('subscription-id')",
"env": "$stageVariables['env']",
"street": $input.json('street'),
"address_name": $input.json('address_name'),
"payment_day": $input.json('payment_day'),
}
As a patch http method, the user's API is not required to pass all the parameters.
So if the user doesn't pass, for e.g. payment_day, the field is going to be ''
. The ''
can be a valid value field. So i have two options:
Is it possible to do this on API Gateway Integration Request -Mapping Template
? Does anyone has a workaround?
Upvotes: 0
Views: 1376
Reputation: 9020
You can use Velocity Conditionals to only output optional values if present.
Alternately, as mentioned in comments, you can just pass the entire JSON body using $input.json('$')
and handle the presence or lack there of inside your Lambda function.
Upvotes: 1