8

Can we create a Rest URL like below in API Gateway?

[GET] /employees?id=1&id=2&id=3&id=4

I do not find a way to send id array and get that array into a lambda (python) function

4 Answers 4

9

this is very late but I had the same issue and found the problem:

From AWS API Gateway Reference:

When a query parameter is a list type, its value must be a string of comma-separated items. For example, GET /restapis/restapi_id/deployments/deployment_id?embed=apisummary,sdksummary.

Amazon API Gateway does not support nested query parameters of the form: GET /team?user[id]=usrid on a method request. You could work around this limitation by passing an encoded map as a single parameter and serializing it as part of a mapping template or in your back-end integration.

So a fix you could use is restructuring your request such that:

[GET] /employees?id=1,2,3,4

Hope this helps!

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

Comments

3

AWS API events have a "multiValueQueryStringParameters" field which can be used instead of "queryStringParameters". It will contain value arrays for all parameters:

idArray = event["multiValueQueryStringParameters"]["id"]

Comments

0

Try sending array with json syntax e.g.: /employees?ids=['1','2','3']

1 Comment

This is not JSON. JSON requires double quotes, not single quotes.
0

This could help in javascript

https://www.npmjs.com/package/amazon-api-gateway-querystring

var mapQueryString = require('amazon-api-gateway-querystring');
event.params.querystring = mapQueryString(event.params.querystring);

event.params.querystring = {
  "person[0][name]": "Mark",
  "person[0][age]": 32,
  "person[1][name]": "Luke",
  "person[1][age]": 26,
  "contacts[home][phone]": "+3333333333",
  "contacts[home][email]": "[email protected]",
  "contacts[home][twitter]": "@username"
}

// become: 

event.params.querystring = {
  "person": [{
    "name": "Mark",
    "age": 32
  }, {
    "name": "Luke",
    "age": 26
  }],
  "contacts": {
    "home": {
      "phone": "+3333333333",
      "email": "[email protected]",
      "twitter": "@username"
    }
  }
}

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.