Numerous services can accept query string parameters in the URL when a POST
request is made with Content-Type: application/x-www-form-urlencoded
and other parameters in the body, but it seems AWS API Gateway cannot while also accepting query string parameters.
When I call the AWS API Gateway with a POST
Mapping Template for application/x-www-form-urlencoded
and query string URL parameters (with a Lambda function), I get the following error:
{
"message":"When Content-Type:application/x-www-form-urlencoded,
URL cannot include query-string parameters (after '?'):
'/prod/webhook?inputType=wootric&outputType=glip&url=...'"
}
Here is an example cURL:
curl -XPOST 'https://{myid}.execute-api.{myregion}.amazonaws.com/prod/webhook? \
inputType=wootric&outputType=glip&url=https://hooks.glip.com/webhook/ \
11112222-3333-4444-5555-666677778888' \
-d "@docs/handlers/wootric/event-example_response-created.txt" \
-H 'Content-Type: application/x-www-form-urlencoded' -v
The specific goal is to get a Wootric webhook event posted to a Lambda function using a URL with query string parameters.
You can get the code here:
https://github.com/grokify/chathooks
The Wootric event body file is here:
https://raw.githubusercontent.com/grokify/chathooks/master/docs/handlers/wootric/event-example_response-created.txt
The GitHub issue is here:
https://github.com/grokify/chathooks/issues/15
The error message seems pretty definitive but I wanted to ask:
If there's no solution to this, is there a good lightweight solution other than deploying a hosted server solution like Heroku. Also, do other cloud services support this with their API gateway + cloud functions, like Google?
Some examples showing support for both:
Amazon API Gateway offers features such as the following: Support for stateful (WebSocket) and stateless (HTTP and REST) APIs. Powerful, flexible authentication mechanisms, such as AWS Identity and Access Management policies, Lambda authorizer functions, and Amazon Cognito user pools.
API Gateway is an AWS service that supports the following: Creating, deploying, and managing a RESTful application programming interface (API) to expose backend HTTP endpoints, AWS Lambda functions, or other AWS services.
An integration request is an HTTP request that API Gateway submits to the backend, passing along the client-submitted request data, and transforming the data, if necessary. The HTTP method (or verb) and URI of the integration request are dictated by the backend (that is, the integration endpoint).
For $method and $integration variables, see Amazon API Gateway API request and response data mapping reference . The following $context variables can be used in data models, authorizers, mapping templates, and CloudWatch access logging.
For AWS Service, choose the service that you're integrating with API Gateway. For example, Simple Notification Service (SNS). (Optional) For AWS Subdomain, enter the subdomain used by the AWS service. Check the service's documentation to confirm the availability of a subdomain.
In the API Gateway console, go back to the Method Execution pane for your API Gateway API's method, and then choose Integration Request. On the Integration Request pane, expand URL Query String Parameters. Choose Add query string.
Valid values include: DELETE , GET, HEAD, OPTIONS , PATCH, POST, and PUT . The AWS account ID associated with the request. For API methods that require an API key, this variable is the API key associated with the method request. For methods that don't require an API key, this variable is null.
Yes,there is a workaround and the key issue is to set the mapping template that will convert string into json . Very detailed example shown in API Gateway any content type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With