0

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:

  • Put a NULL value on the payment_day field.
  • Remove the payment_day from JSON request.

Is it possible to do this on API Gateway Integration Request -Mapping Template? Does anyone has a workaround?

1
  • You could just pass the entire JSON body to your Lambda function (using $input.json('$') and sort it out in the Lambda function. Commented Mar 16, 2016 at 15:48

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.