Create a new Function

POST /groups/{groupId}/apps/{appId}/functions

Create a new Function.

Path parameters

application/json

Body Required

The function to create

  • can_evaluate object

    A JSON expression that evaluates to true if the Function is allowed to run in response to an incoming request.

  • name string Required

    A unique name for the Function.

  • private boolean Required

    If true, the function is hidden from client applications. You can still call a private function from JSON expressions and other functions, including incoming webhooks and triggers.

  • source string Required

    The stringified source code for the function. The code must be valid ES6.

  • run_as_system boolean

    If true, the function executes with full privileges, bypassing rules on all services.

  • run_as_user_id string

    An application user's account ID. If defined, endpoints will always run as the specified user. Cannot be used with run_as_user_id_script_source.

  • run_as_user_id_script_source string

    The stringified source code for a function that returns an application user's account ID. If defined, endpoints execute the function on every request and run as the user with the ID returned from the function. Cannot be used with run_as_user_id.

Responses

  • 201 application/json

    The function was successfully created.

    Hide response attributes Show response attributes object
    • _id string

      Unique identifier for the function.

    • name string

      Name for the function specified in the name field of the request.

POST /groups/{groupId}/apps/{appId}/functions
curl \
 --request POST 'https://services.cloud.mongodb.com/api/admin/v3.0/groups/{groupId}/apps/{appId}/functions' \
 --header "Authorization: Bearer $ACCESS_TOKEN" \
 --header "Content-Type: application/json" \
 --data '{"can_evaluate":{},"name":"string","private":true,"source":"string","run_as_system":true,"run_as_user_id":"string","run_as_user_id_script_source":"string"}'
Request examples
{
  "can_evaluate": {},
  "name": "string",
  "private": true,
  "source": "string",
  "run_as_system": true,
  "run_as_user_id": "string",
  "run_as_user_id_script_source": "string"
}
Response examples (201)
{
  "_id": "string",
  "name": "string"
}