Functions
Create function
Create a new serverless function. Trigger types: http, document, file, webhook, wallet, cron, messaging. Sandbox globals available today: `payload`, `context`, `env`, `console`. Function code runs in an isolated worker with no ambient network or database access — it can only read its trigger payload, the `env` vars you configure, and return a JSON-serializable result; it cannot yet call back into your project's database, storage, messaging, or wallet APIs from inside the function body. If you need to read or write project data from a function, call the regular REST API (with your own API key) from your own backend in response to the function's returned result, rather than from within the function's own code.
/api/functions/projects/{projectId}/functionsSDK setup
Create a client and set credentials (JWT and/or API key) before calling the API. Match the authentication type shown above.
import { Configuration, FunctionsApi } from 'mudbase-sdk';
const configuration = new Configuration({
basePath: 'https://cloud.mudbase.dev',
apiKey: 'sk_live_mudbase_doc_Xk9mP2qR7vN4wL8jH3tY6uE',
accessToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c3JfbW9yZ2FuX2RlIiwiZW1haWwiOiJtb3JnYW4uY2hlbkBub3J0aHdpbmQuZGV2IiwiZXhwIjoxODI1MTI5NjAwfQ.doc_preview_sig',
});
// This endpoint accepts either credential — apiKey or accessToken alone is enough.
const functions = new FunctionsApi(configuration);import { Configuration, FunctionsApi } from 'mudbase-sdk';
const configuration = new Configuration({
basePath: 'https://cloud.mudbase.dev',
apiKey: 'sk_live_mudbase_doc_Xk9mP2qR7vN4wL8jH3tY6uE',
accessToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c3JfbW9yZ2FuX2RlIiwiZW1haWwiOiJtb3JnYW4uY2hlbkBub3J0aHdpbmQuZGV2IiwiZXhwIjoxODI1MTI5NjAwfQ.doc_preview_sig',
});
// This endpoint accepts either credential — apiKey or accessToken alone is enough.
const functions = new FunctionsApi(configuration);Example request
Call this endpoint using the client from SDK setup. Use View HTTP for a raw cURL example.
const { data: result } = await functions.createFunction(
"proj_1bEuXnMAVOkm",
{
name: "Dale Kunde-Lueilwitz III",
description: "Savor the spicy essence in our Towels, designed for grimy culinary adventures",
code: "microchip navigate",
trigger: "protocol back up",
environment: "hard drive reboot"
}
);const { data: result } = await functions.createFunction(
"proj_1bEuXnMAVOkm",
{
name: "Dale Kunde-Lueilwitz III",
description: "Savor the spicy essence in our Towels, designed for grimy culinary adventures",
code: "microchip navigate",
trigger: "protocol back up",
environment: "hard drive reboot"
}
);Playground
liveTest this endpoint with your own credentials. Your requests will be sent to the live API.
No Request Yet
Send a request to see the full inspector
Authentication
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
| Name | Type | Required | Description |
|---|---|---|---|
projectId | string | Yes | — |
Request Body
{
"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": {}
}Responses
{
"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"
}
}