How to map an array or object from Api Gateway integration request mapping template?

Viewed 1632

I have POST method in API Gateway that accepts the data passed from body params.

enter image description here

From the API Gateway, I managed to get the userName and uuid, but I'm having an error getting the traveledCities. How can I map an array or an object passed from body params

enter image description here

I'm getting an error from $inputRoot.traveledCities line 5

1 Answers

You have to define the template directly with the array field. Here an example:

Request:

POST apigateway/stage/resource?query=test
{
  "id": "id",
  "list": [1,2,3,4]
}

Mapping:

#set($inputRoot = $input.path('$'))
{
  "query": "$input.params('query')",
  "id": "$inputRoot.id",
  "list": $inputRoot.list
}
Related