functions

Create function

Create a new serverless function. Trigger types: http, document, file, webhook, wallet, cron, messaging. Sandbox utilities available: db, files, messaging, wallet, utils, env, console.

POST/api/functions/projects/{projectId}/functions

Authentication

Requires JWT Requires API Key JWT or API Key
Note
This endpoint accepts either JWT Bearer token or API Key. Use Authorization: Bearer YOUR_TOKEN for user context, or X-API-Key: YOUR_KEY for server-to-server. View authentication guide →Include your JWT in the Authorization: Bearer YOUR_TOKEN header (user-facing apps, RBAC). View authentication guide →Include your API key in the X-API-Key: YOUR_KEY header (server-to-server, SDKs). View authentication guide →

Path Parameters

NameTypeRequiredDescription
projectIdstringYesProject ID.

Request Body

Function name, description, code, trigger config, and optional environment.

json
{
  "name": "Johnathan Torp I",
  "description": "Introducing the French Polynesia-inspired Towels, blending amazing style with local craftsmanship",
  "code": "interface synthesize",
  "trigger": {
    "type": "file",
    "event": "monitor connect",
    "schedule": "system quantify",
    "path": "driver navigate",
    "method": "GET",
    "collectionId": "zPwbK8nwmu0GtkJ3",
    "bucketId": "jr8VDj0iot8K8Qmz"
  },
  "environment": {}
}
{
  "name": "Johnathan Torp I",
  "description": "Introducing the French Polynesia-inspired Towels, blending amazing style with local craftsmanship",
  "code": "interface synthesize",
  "trigger": {
    "type": "file",
    "event": "monitor connect",
    "schedule": "system quantify",
    "path": "driver navigate",
    "method": "GET",
    "collectionId": "zPwbK8nwmu0GtkJ3",
    "bucketId": "jr8VDj0iot8K8Qmz"
  },
  "environment": {}
}

SDK setup

Create a client and set credentials (JWT and/or API key) before calling the API. Match the authentication type shown above.

import { MudbaseClient } from "mudbase";

const client = new MudbaseClient();
client.setJWT("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c3JfbW9yZ2FuX2RlIiwiZW1haWwiOiJtb3JnYW4uY2hlbkBub3J0aHdpbmQuZGV2IiwiZXhwIjoxODI1MTI5NjAwfQ.doc_preview_sig");
import { MudbaseClient } from "mudbase";

const client = new MudbaseClient();
client.setJWT("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c3JfbW9yZ2FuX2RlIiwiZW1haWwiOiJtb3JnYW4uY2hlbkBub3J0aHdpbmQuZGV2IiwiZXhwIjoxODI1MTI5NjAwfQ.doc_preview_sig");

Example request

Call this endpoint using the client from SDK setup. Use View HTTP for a raw cURL example.

const result = await client.functions.create({
  projectId: "proj_vuDmWbfWQ6Qz",
  name: "Kristin Bogan",
  code: "hard drive generate",
  trigger: "pixel compress",
  description: "Our butterfly-friendly Tuna ensures winding comfort for your pets",
  environment: "program copy"
});
const result = await client.functions.create({
  projectId: "proj_vuDmWbfWQ6Qz",
  name: "Kristin Bogan",
  code: "hard drive generate",
  trigger: "pixel compress",
  description: "Our butterfly-friendly Tuna ensures winding comfort for your pets",
  environment: "program copy"
});

Try It Live

Test this endpoint with your own credentials. Your requests will be sent to the live API.

Get your API key from the console
Use the auth endpoints to obtain a JWT.

No Request Yet

Send a request to see the full inspector

Responses

201Function created
json
{
  "success": true,
  "data": {
    "_id": "685af8b85d73a104065b6a77",
    "name": "OnUserCreate",
    "trigger": {
      "type": "document",
      "event": "create",
      "collectionId": "685ada8fd9416ac02f171abf"
    },
    "project": "685ad30be129932fbb7a1047",
    "isActive": true,
    "versions": [
      {
        "version": 1,
        "comment": "Initial version"
      }
    ],
    "createdAt": "2024-01-15T10:00:00.000Z"
  }
}
{
  "success": true,
  "data": {
    "_id": "685af8b85d73a104065b6a77",
    "name": "OnUserCreate",
    "trigger": {
      "type": "document",
      "event": "create",
      "collectionId": "685ada8fd9416ac02f171abf"
    },
    "project": "685ad30be129932fbb7a1047",
    "isActive": true,
    "versions": [
      {
        "version": 1,
        "comment": "Initial version"
      }
    ],
    "createdAt": "2024-01-15T10:00:00.000Z"
  }
}
400Bad request or validation error.
401Authentication required or invalid token.
403Access denied or insufficient permissions.

Errors

CodeMeaning
400Bad request or validation error.
401Authentication required or invalid token.
403Access denied or insufficient permissions.
Edit this page on GitHub