Lambda functions query string params not working

I am new to Lambda functions but am really excited about them and am trying to utilize them to make an API call in an old vanilla JS project. I am using the unsplash API to dynamically query what the user types in. I can get the function to work, and can hard code the query string parameters, and the site will function properly. however, I am unable to get any value on the event object and it always returns empty.


 search = (searchTerm) => {
  return fetch(`/.netlify/functions/token-hider?search=${searchTerm}`)
    .then((response) => response.json())
    .then((result) => {
      result.results.forEach((image) => {
        const galleryItem = document.createElement("div");
        galleryItem.className = "gallery-item";
        const imageDiv = document.createElement("div");
        imageDiv.className = "image-div";
        imageDiv.innerHTML =
          "<img class='image' src=" + image.urls.regular + ">";
        form.addEventListener("submit", (e) => {

      return results;

form.addEventListener("submit", (e) => {
  let searchTerm = input.value;


const axios = require("axios");
const qs = require("qs");

exports.handler = async function (event, context) {
  // apply our function to the queryStringParameters and assign it to a variable
  const API_PARAMS = qs.stringify(;
  // const API_PARAMS = qs.stringify(event.queryStringParameters);
  console.log("API_PARAMS", API_PARAMS);
  // Get env var values defined in our Netlify site UI

  // TODO: customize your URL and API keys set in the Netlify Dashboard
  // this is secret too, your frontend won't see this
  const { KEY } = process.env;
  const URL = `${KEY}&query=${API_PARAMS}`;

  console.log("Constructed URL is ...", URL);

  try {
    const { data } = await axios.get(URL);
    // refer to axios docs for other methods if you need them
    // for example if you want to POST data:
    //'/user', { firstName: 'Fred' })
    return {
      statusCode: 200,
      body: JSON.stringify(data),
  } catch (error) {
    const { status, statusText, headers, data } = error.response;
    return {
      statusCode: error.response.status,
      body: JSON.stringify({ status, statusText, headers, data }),

I am able to log out everything but the query string params. the environmental variables i set in the UI seem to be working… Am I passing the params wrong in the query string?

Hello @Ren, welcome to the community!

It looks like you are trying to log out API_PARAMS which depends on if the ‘search’ key is exists. Could you try assigning that var to qs.stringify(event.queryStringParameters) to see if there is a ‘search’ key in there or not?