amplify-js: Cannot get API.get to work

Hello,

I’m trying to use API.get and pass queryStringParameters in the request so these params can be accessed from Lambda function’s ‘event’ but this doesn’t seem to work.

    const val1 = 'test123';
    const val2 = 'test123';

    let myInit = {
        'queryStringParameters': {
            'key1': val1,
            'key2': val2
        },
        headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json',
        }
    };

    return API.get(apiName, path, myInit).then(data => {
        return data;
    }).catch(err => console.log('error.', err));

Notes:

  1. I’ve added the query params in Api Gateway method (URL Query String Parameters)
  2. In Lambda function’s logs i can see queryStringParameters: null,
  3. API Gateway Integration request details (Use Lambda Proxy integration is enabled) image
  4. I’ve tried adding the query params as part of path as abc?key1=val1&key2=val2 etc. but didn’t work as well
  5. API.post works good (when passing the params in body

Let me know if you need more details

Thanks in advance.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 27 (3 by maintainers)

Most upvoted comments

@marioskonstantinou suppose that your path is const path = '/users';, if you want to include a param called email you simply append the param to the path. Now it becomes const path = '/users?email=example@email.com';

Okay so a colleague of mine figured out that the parameter values need to be URL encoded for this to work. I had a colon (:) in one of my values which resulted in me getting that signature calculation error.

Once I url encoded the colon (to %3A), the request returned a successful response.

Hope this helps anyone!

Sure! That will save me from having to make an additional PR 😃 Looking forward to seeing the change merged in!

Hi there, Thanks for the fix, any chance to get that merged ? It’s very disturbing miss…

@marioskonstantinou I have a React Native example here that should work until queryStringParameters is supported:

const apiName = 'http://myendpoint.com'
const path = `/my/path?param1=${value1}&param2=${value2}`
API.get(apiName, path)
    .then((response) => {
        resolve(response)
    },
    (err) => {
        console.log('err resp', err)
        resolve(err)
    })