HTTPS Endpoint can't access querystring

Hi

I have a number of HTTPS endpoints which I recently converted over from the deprecated webhooks. The endpoints need to be authenticated using an api key as part of the query string e.g.
https://data.mongodb-api.com/app/name/endpoint/config?apiKey=1234

In the linked function, I have Authentication set to script and the script looks something like this…

exports = function(payload, response) {
  console.log(JSON.stringify(payload));
  const {apiKey} = payload.query;
  if(apiKey == null) {
    return "";
  }
  return context.functions.execute("checkAPIKey", apiKey);
};

However, I get an error in the logs “TypeError: Value is not object coercible” and the logged value of payload is empty {} so I can’t read the API key value. In the Endpoint Query Arguments part of the logs I see the apiKey listed fine. I can use context.request.rawQueryString and see the full value of the query string which I could process myself but it shouldn’t have to work like that. This all worked fine in the previous webhook.

Also as a curiosity and not necessarily a problem, I can’t use async await or ?. syntax in the function (like it is using an old version of ECMAScript). It’s not a big deal for me but it used to work fine in the webhook.

Any help much appreciated.

Thanks

Hi Simon - thanks for the report. We identified these as bugs and have filed them as tickets to fix. Good catch! Will let you know when these get updated.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.