HTTP Service Get Webhook does not receive queryString

Hi,

I’m new to MongoDB and have been working through the below example with AppGyver.
[Realm Serverless platform integration with No-Code Composer from AppGyver](Realm Serverless platform integration with No-Code Composer from AppGyver - By Pavel Duchovny and Harri Sarsa)

Everything has gone great, except when I got to the section to get a list of movies using the GetMovies webhook. The sample code as documented is below…

    /*
   This API searches movies from db("sample_mflix").collection("movies") using Atlas Search aggregation
*/
exports = async function(payload, response) {

 // Extract, the search query param
 const {Search} = payload.query;
 var filter;

 // Get the collection object
 const movies = await context.services.get("mongodb-atlas").db("sample_mflix").collection("movies");
 var doc = [];

    console.log(`ID ${Search}`);
    // If Search term is not empty use atlas search $search operator
    if (Search !== "")
    {
      filter = [{
          '$search': {
            'text': {
              'path': ['title', 'plot','fullplot','generes'],
              'query': Search,
              'fuzzy': {}
            }
        }
      },{"$limit" : 100}];
       doc = await movies.aggregate(filter).toArray();
    }
    else
    {
       // If no Search term provided return first found 100 results
       doc = await movies.aggregate([{"$limit" : 100}]).toArray();
    }

    // Return the found documents through the response object
    response.setBody(JSON.stringify(doc));
    response.setStatusCode(200);

};

The problem I am having is that payload.query always is an empty string - so nothing is returned.

I have been using Postman to call the webhook, to remove AppGyver from the equation and the result returned is always an empty array [].

This is the request I make…
https://ap-southeast-2.aws.webhooks.mongodb-realm.com/api/client/v2.0/app/moviesapp-zcjuo/service/MoviesAPI/incoming_webhook/GetMovies?Search=Horse

I’ve done a fair bit of reading, but can’t figure out why it’s not working.

This is the log output.

Logs:
[
  "ID "
]
Function Call Location:
AU
Query Arguments:
{
  "Search": ""
}
Headers:
{
  "Content-Type": [
    "application/json"
  ],
  "Accept": [
    "*/*"
  ],
  "Accept-Encoding": [
    "gzip, deflate, br"
  ],
  "Accept-Language": [
    "en-GB"
  ],
  "X-Forwarded-Proto": [
    "https"
  ],
  "X-Cluster-Client-Ip": [
    "111.11.11.11"
  ],
  "User-Agent": [
    "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_16_0) AppleWebKit/537.36 (KHTML, like Gecko) AppGyver/1.8.1 Chrome/78.0.3904.130 Electron/7.1.14 Safari/537.36"
  ],
  "Sec-Fetch-Site": [
    "cross-site"
  ],
  "Sec-Fetch-Mode": [
    "cors"
  ],
  "X-Forwarded-For": [
    "111.11.11.11"
  ],
  "X-Envoy-External-Address": [
    "111.11.11.11"
  ],
  "X-Request-Id": [
    "ecf6ed27-b79e-4b40-8d4a-56cd1829835f"
  ]
}
Compute Used:
24193082 bytes•ms
Remote IP Address:
111.11.11.11
Rule Performance Metrics:
{
  "sample_mflix.movies": {
    "no_matching_role": 0
  }
}

It may be that MongoDB Realm has changed which is why the code doesn’t work, as this article was written about a year ago now.

If anyone can see the issue, I’d love to know. Being able to return a set of results is a pretty fundamental requirement to my (or any) app!

Thanks

1 Like

Hi and welcome @KapaiNZ ! I am also pretty new to MongoDB but this is the place to get the answer you need. I’m sure someone will be able to direct you soon. I have been helped tremendously by the community in my journey. Thanks also for the link to learn more about Realm serverless platform integration with no-code composer from AppGyver From the above link…Very interested in that! Welcome to the community and Happy learning!

1 Like

Hi @Jason_Nutt and @KapaiNZ ,

I understand the issue of the article. I missed the section of adding a search index for this to work.

Thanks
Pavel

1 Like