How to pass a parameter to Realm function from Https Endpoints

I have a Realm function that using the testing console is invoked as exports({“userId”: “638cea4bd157479ec554d9b9”}). Within the function I get the object id as

data.userId and the function works as expected.

Now if I expose the Realm function as an Https Endpoint how would I specify this?

curl
-H “Content-Type: application/json”
-d ‘{“userId”: “638cea4bd157479ec554d9b9”}’
endpoint_url

returns an error:

{“error”:“{"message":"ObjectId in must be a single string of 12 bytes or a string of 24 hex characters","name":"Error"}”,“error_code”:“FunctionExecutionError”,“link”:“App Services”}%

The value is null because it isn’t being passed to REALM

OK. I figured it out:

From curl:

curl \
-H "Content-Type: application/json" \
-d '{"query": {"userId": "63dcd7a0766580205fe7869d"}}' \
https://data.mongodb-api.com/app/data-XXX/endpoint/feed

Wiithin the function:

exports = async function(request, response){
  console.log( "Request: " + JSON.stringify(request))
 const body = JSON.parse(request.body.text());
 const userId = body.query.userId;
2 Likes

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