Serverless Functions & Webhooks

Functions and webhooks let users automate work around their data. Functions run custom backend logic. Webhooks notify external systems when something important happens.

Functions

Functions are managed per cluster from:

Example
/functions/{clusterId}

The page calls these backend routes:

TaskBackend route
List functionsGET /api/clusters/{clusterId}/functions
Create functionPOST /api/clusters/{clusterId}/functions
Update functionPUT /api/clusters/{clusterId}/functions/{functionId}
Delete functionDELETE /api/clusters/{clusterId}/functions/{functionId}
Test functionPOST /api/clusters/{clusterId}/functions/{functionId}/test
Execute functionPOST /api/clusters/{clusterId}/functions/{functionId}/execute
View logsGET /api/clusters/{clusterId}/functions/{functionId}/logs

Function Shape

A function should be written as small, predictable backend logic. Use it for validation, enrichment, notifications, data transformations, or controlled integrations.

Example:

JavaScript
export default async function handler(context) {
  const { db, input, user } = context;

  const customer = await db.collection("customers").findOne({
    email: input.email,
  });

  if (!customer) {
    return { ok: false, reason: "customer_not_found" };
  }

  return {
    ok: true,
    customerId: customer._id,
    plan: customer.plan,
    requestedBy: user.email,
  };
}

Test A Function

From the dashboard:

Example
1. Open /cluster/{clusterId}
2. Click Functions
3. Create or edit a function
4. Use Test
5. Open Logs for the function

From the API explorer:

Example
Test in API explorer
Open /api-docs
Authorize
Try POST /api/clusters/{clusterId}/functions/{functionId}/test

From curl:

Terminal
Test in API explorer
curl -X POST https://credvault-production.up.railway.app/api/clusters/<clusterId>/functions/<functionId>/test \
  -H "Authorization: Bearer <your-session-token>" \
  -H "Content-Type: application/json" \
  -d '{"email":"ada@example.com"}'
What you should seeA JSON response, an HTTP status, or a clear authentication or permission error.

What you should see: the function result as JSON, plus a log entry for the test run. For the example above, a found customer returns ok: true; a missing customer returns ok: false with a reason.

Webhooks

Webhooks are managed from:

Example
/webhooks/{clusterId}

The page calls:

TaskBackend route
List webhooksGET /api/webhooks
Create webhookPOST /api/webhooks
Update webhookPUT /api/webhooks/{webhookId}
Delete webhookDELETE /api/webhooks/{webhookId}
Test webhookPOST /api/webhooks/{webhookId}/test
View deliveriesGET /api/webhooks/{webhookId}/deliveries
Regenerate secretPOST /api/webhooks/{webhookId}/regenerate-secret

Webhook Payload

A webhook delivery should be treated like an external API call. Verify the signature before trusting the body.

Example receiver:

JavaScript
import crypto from "node:crypto";
import express from "express";

const app = express();
app.use(express.raw({ type: "application/json" }));

app.post("/credvault/webhook", (req, res) => {
  const signature = req.header("X-CredVault-Signature");
  const expected = crypto
    .createHmac("sha256", process.env.CREDVAULT_WEBHOOK_SECRET)
    .update(req.body)
    .digest("hex");

  if (signature !== expected) {
    return res.status(401).json({ error: "invalid_signature" });
  }

  const event = JSON.parse(req.body.toString("utf8"));
  console.log("CredVault event:", event.type);
  res.json({ received: true });
});

Test A Webhook

Use the dashboard:

Example
1. Open /webhooks/{clusterId}
2. Create a webhook with a public HTTPS URL
3. Select events
4. Press Test
5. Open Deliveries to inspect status and response time

Use the CLI:

Terminal
cie webhooks list
cie webhooks create
cie webhooks test <webhook-id>

What you should see: the CLI should print the webhook ID, delivery status, HTTP response code, and response time. In the dashboard, the same delivery should appear under webhook deliveries.

When To Use Each

NeedUse
Run custom logic inside CredVaultFunction
Notify another productWebhook
Transform data on a schedulePipeline or function
Connect to Slack, CRM, billing, or warehouseWebhook
Validate or enrich a document before downstream useFunction

Security Rules

  • Use HTTPS webhook URLs.
  • Store webhook secrets in environment variables.
  • Rotate webhook secrets after sharing or incident response.
  • Keep functions small and idempotent.
  • Do not log secrets or payment data.
  • Use activity logs to audit creation, update, test, and delete actions.