Skip to content

Triggers Overview

Microfn functions can be invoked through multiple trigger mechanisms, allowing you to execute your serverless code in response to various events and conditions. Each trigger type serves different use cases and integration patterns.

Microfn supports three primary trigger types:

Trigger TypeDescriptionUse Cases
HTTP WebhooksDirect invocation via HTTP POST requestsAPIs, integrations, real-time processing
Scheduled (Cron)Time-based automatic executionBatch jobs, maintenance, reports
EmailTrigger functions by sending emailsEmail automation, notifications, workflows
FeatureWebhooksCronEmail
InvocationHTTP POSTAutomatic scheduleSend email
InputJSON payloadEmpty {} or customEmail data
AuthenticationBearer token / PublicN/A (internal)Email address
ResponseSynchronousN/A (async)N/A (async)
Rate LimitingYesSchedule-basedYes
SetupAutomaticConfigure scheduleGenerate address

HTTP webhooks provide direct, synchronous function execution:

Terminal window
curl -X POST https://microfn.dev/run/username/function-name \
-H "Content-Type: application/json" \
-d '{"input": "data"}'

Best for:

  • REST APIs
  • Third-party integrations
  • Real-time processing
  • Synchronous workflows

Cron triggers execute functions automatically on a schedule:

// Configured in workspace settings
// Cron expression: "0 9 * * *" (daily at 9 AM)
export default async function main() {
// Function receives empty input {}
await performDailyTasks();
return { success: true };
}

Best for:

  • Scheduled reports
  • Data synchronization
  • Cleanup tasks
  • Recurring workflows

Email triggers execute functions when emails are received:

// Email sent to: ws-abc123xyz@mail.microfn.dev
export default async function main(input) {
// input contains email data
const { from, subject, body } = input;
await processEmail(from, subject, body);
return { processed: true };
}

Best for:

  • Email automation
  • Support tickets
  • Notification processing
  • Email-to-task conversion
  • You need immediate, synchronous responses
  • Integrating with external services
  • Building REST APIs
  • Handling user-initiated actions
  • Tasks run on a regular schedule
  • No external input is needed
  • Performing batch operations
  • Running maintenance tasks
  • Integrating with email workflows
  • Processing incoming notifications
  • Converting emails to actions
  • Building email-based automation

Functions can be triggered through multiple mechanisms:

export default async function main(input) {
// Determine trigger source
const triggerSource = input.triggerSource || "webhook";
switch (triggerSource) {
case "cron":
// Scheduled execution logic
return await handleScheduledRun();
case "email":
// Email trigger logic
return await processEmail(input);
default:
// Webhook logic
return await handleWebhook(input);
}
}

Each trigger type has different security implications:

  • Use authentication tokens for private functions
  • Validate input data
  • Implement rate limiting
  • Use HTTPS always
  • Runs with workspace permissions
  • No external access needed
  • Secure by default
  • Unique, unguessable email addresses
  • Validate sender if needed
  • Process untrusted content safely
  • Implement spam protection

All trigger executions are logged with:

  • Trigger type and source
  • Execution time and duration
  • Input parameters
  • Output and errors
  • Usage metrics

Access logs through:

  • Microfn dashboard
  • Execution history API
  • Real-time monitoring

Trigger limits vary by subscription tier:

LimitFreeProEnterprise
Webhook calls/month10,000100,000Unlimited
Cron jobs550Unlimited
Email triggers110Unlimited
Min cron interval1 hour5 minutes1 minute
  1. Choose the right trigger for your use case
  2. Implement error handling for all trigger types
  3. Log trigger source for debugging
  4. Set up monitoring for critical triggers
  5. Test thoroughly with each trigger type
  6. Document trigger requirements in your function
  7. Use appropriate timeouts for long-running tasks

Explore each trigger type in detail: