Can't get HTTP Webhook to work - 400 Bad Request - Using HttpClient in C#

I am using HTTPS with a webhook in MongoDB Realms.

I have set up the MongoDB database, with a collection.

I have also used the MongoDB.Bson and MongoDB.driver with a C# Application and successfully read/write data to and from the database/collection.

However, I am in need of using Realms because I am using webgl in Unity. webgl does not allow for these drivers, thus I must make an http request.

So I decided to try using HttpClient, below is my code:

(I don’t mind showing my passkeys or api keys because I can change them later.)

    static async Task Main(string[] args) {

        Console.WriteLine("Hello World!");

        string getURLwebhook = "https://ap-southeast-1.aws.webhooks.mongodb-realm.com/api/client/v2.0/app/application-0-eprrf/service/ConnectToDataBaseOverHTTP/incoming_webhook/getTEST?secret=secreatPassPhraseForYou1234";
        // getURLwebhook = "http://www.contoso.com/"; // testing

        using (var requestMessage = new HttpRequestMessage(HttpMethod.Get, getURLwebhook)) {
            requestMessage.Headers.Authorization = new AuthenticationHeaderValue("api-key", "bNKzoZTHRdDGLVrBCywr9avGbl5bvufY58uG3yxOtux4juStNNeLgteQf66i3MOs");

            string contentType = "application/json";

            requestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(contentType));

            HttpResponseMessage responseMessage = await client.SendAsync(requestMessage);

            responseMessage.EnsureSuccessStatusCode();

            Console.WriteLine(responseMessage);

            string responseBody = await responseMessage.Content.ReadAsStringAsync();

            Console.WriteLine(responseBody);
        } }

Here is my code in the Realm WebHook Function

exports = function(payload, response) {
  
  
  const mongodb = context.services.get("mongodb-atlas");
  const mycollection = mongodb.db("AccountCooldowns").collection("AccountCooldownCollection");
  response.setStatusCode(200)
  
  return mycollection.find({}).limit(10).toArray();

}

When running this code with the run button, it works perfectly.

Here are my settings:

When I run the C# code it will always return this error:


400 Bad Request

There are numerous topics all having this same issue, but without answers. I would link it, but I cannot link more than two things at a time per post as I am a new user.

I have followed the 10 minute tutorial, but it did not work.