Skip to content

How to pass both headers and query parameters in GET request in API Gateway

0

I have a GET request which uses some Query Parameters and I'm trying to pass in headers as well in API Gateway, but seems like I'm not able to access Headers.

If I pass in a header like this:

"get" : {
        "parameters" : [ {
          "name" : "custom-header",
          "in" : "header",
          "schema" : {
            "type" : "string"
          }
        }],
       "x-amazon-apigateway-integration" : {
          ...
         "httpMethod" : "GET",
          "requestParameters" : {
            "integration.request.header.custom-header" : "method.request.header.custom-header"
          },
         ...
       }
...
}

without passing in any query string parameters, it works and I can see headers passing through in GET request.

However, when I try to do the following:

"get" : {
        "parameters" : [ {
          "name" : "custom-header",
          "in" : "header",
          "schema" : {
            "type" : "string"
          }
        },
       {
          "name" : "query_param",
          "in" : "query",
          "schema" : {
            "type" : "string"
          }
        },

        ],
       "x-amazon-apigateway-integration" : {
          ...
         "httpMethod" : "GET",
          "requestParameters" : {
             "integration.request.querystring.query_param" : "method.request.querystring.query_param",
            "integration.request.header.custom-header" : "method.request.header.custom-header"
          },
         ...
       }
...
}

It does not work, i.e. I do not see the headers being passed through in the GET request.

On this documentation page by AWS here, it is stated that to use query parameters and headers in GET request, it is defined as POST request and the httpMethod is defined as GET. Does this mean I'm unable to use query parameters and headers together in GET requests? and have to switch to POST?

1 Answer
1

You can definitely pass both headers and query parameters in a GET request in API Gateway. The issue you're experiencing is likely related to how you're configuring the parameter mappings.

To pass both headers and query parameters in a GET request:

  1. In your API Gateway configuration, make sure both the header and query parameters are properly defined in the Method Request section.

  2. Then in the Integration Request section, map both the header and query parameters correctly:

For headers:

"integration.request.header.custom-header": "method.request.header.custom-header"

For query parameters:

"integration.request.querystring.query_param": "method.request.querystring.query_param"

Your configuration looks correct based on what you've shared. A few things to check:

  • Make sure you're actually sending the custom header in your test requests
  • Verify that your API has been redeployed after making these changes
  • Check if there are any caching issues affecting your tests

API Gateway fully supports passing both headers and query parameters in GET requests - you don't need to switch to POST. The documentation you referenced is likely showing a specific use case for transforming a POST request to a GET request at the integration level, not suggesting that you can't use headers with GET requests.

If you're using the AWS console, you can also try:

  1. Go to the Method Request configuration
  2. Add both your header and query parameter there
  3. Then in Integration Request, map both parameters as shown above
  4. Save and deploy your API

API Gateway supports multi-value headers and parameters, so there shouldn't be any technical limitation preventing you from using both in a GET request.
Sources
Passing X-Forwarded-Host and X-Forwarded-Port headers from API Gateway | AWS re:Post
Transform API requests and responses for HTTP APIs in API Gateway - Amazon API Gateway
Lambda proxy integrations in API Gateway - Amazon API Gateway
Tutorial: Create a REST API with an HTTP non-proxy integration - Amazon API Gateway

answered a year ago

EXPERT

reviewed a year ago

  • Well I've definitely made sure that my mappings looks completely correct. In Method Request Section, under URL query string parameters I see query_param under name and under HTTP request headers I see custom-header under Name

    and

    In Integration Request section, the mappings also looks correct with query params as query_param method.request.querystring.query_param and header as custom-header method.request.header.custom-header

    and as I mentioned, I used the same header config for another GET request which didn't have query parameters, I was able to see the headers being passed in that one. Not sure why this specific GET request with both query params and headers is not working

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.