1

I'm looking for the hash equivalent of this question: How to pass array query params to AWS API Gateway?

Basically, I want to set up query parameters that look like this: example.com?color[background]=yellow&color[foreground]=black

When I try to create a query parameter called color[background] in the API Gateway console, I get the following error message: Invalid mapping expression specified: Validation Result: warnings : [], errors : [Parameter name should be a non-empty alphanumeric string]

I've also tried setting up a color query param and then passing various "hashes" to it. Here's what I've tried passing into this parameter:

  1. {"background" => 123, "foreground" => "abc"} and removing the spaces
  2. {"background" : 123, "foreground" : "abc"} and removing the spaces
  3. {background:123,foreground:abc}

They all result in a request that is some form of example.com?color=%7Bbackground:123,foreground:abc%7D with the hash that I pass coming after the =.

Any ideas? Is this bad practice for query string parameters anyways, and should I stick with simple params?

2
  • 1
    You can pass a hash but you can't expect API Gateway to understand what you intend it to mean... it's just a string value at that point... but... does it support dots in key names? I'd be inclined to use ?color.background=yellow&color.background=black for readability if I were just designing the API for no specific platform, but that may not be "alphanumeric" depending on how loosely they are using the term. Apr 30, 2016 at 4:22
  • @Michael-sqlbot -- Thanks! I'm going to go with something like this.
    – readyornot
    May 2, 2016 at 21:01

1 Answer 1

1

Since there isn't a standard defined to pass in complex data structures like arrays or maps via the query string, API Gateway does not attempt to to interpret or parse the query string as anything other than simple key-value string pairs.

If you want to pass in and transform complex types it's best to do so in the body of a POST or PUT request where you can leverage JSON and API Gateway's powerful body mapping templates feature.

Alternatively, if you must stick with query string parameters, then you must either:

  1. Collapse your data structure to be simple key value pairs as suggested by Michael -sqlbot above, or
  2. Passthrough the raw query string to your backend lambda or http integration where it can parsed as you please. See this post for more details on how to do that.
1
  • Makes sense. I can tweak my backend to handle this. Thanks!
    – readyornot
    May 2, 2016 at 21:01

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.