Events and triggers

Events and triggers

Mashlets can be run in four ways:

ModeWhen the mashlet runs
ManualThe user runs it from the script editor, or picks it from a file’s action menu.
ScheduledA cron (or daily/weekly/monthly) schedule fires the mashlet against a configurable list of files. The schedule’s file_source.
EventThe mashlet is bound to a system event (file uploaded, mail received, user signed in, etc.) and runs each time that event fires.
WebhookAn HTTP request to a per-hook URL fires the mashlet, with the request body and headers available inside the script.

Manual and scheduled triggers are configured in Foldr Settings > Automation, alongside the mashlet itself. Event and webhook triggers are configured in the same screen by attaching the mashlet to an event or hook.

Scheduled triggers and file_source

A scheduled mashlet runs against a list of files resolved at run time from its file_source configuration. Four modes are available:

typeResolves to
folderEvery file in a folder on a given share.
globFiles in a folder whose names match a glob pattern.
field_filterFiles (cross-share) whose custom field values match a filter set.
explicitA hand-picked list of (share_id, path) entries.

The resolver enforces a soft cap of 1000 files per run to prevent runaway expansion; if a file_source resolves to more, the mashlet’s mash.event.files_truncated flag is set so the script can react. If you genuinely need to process more than 1000 files in one go, split into multiple scheduled mashlets or batch via field filters.

Event triggers

When a mashlet is bound to an event, Foldr fires it each time that event occurs. The event’s payload (the file, user, mail, etc.) is available inside the script through mash.event.

File events

EventWhen it fires
UploadedA file is uploaded through the Foldr web app, desktop app, or the API.
DownloadedA file is downloaded from the Foldr web app or opened via a native Foldr app.
IndexedThe Foldr search index successfully indexes a file. If Captur is in play, any extracted data is available alongside the file.
CrawledThe crawler visits a file (whether or not it ends up indexed). Useful for housekeeping that should happen once per crawl pass regardless of indexing outcome.
MovedA file is moved to a new location.
CopiedA file is copied.
DeletedA file is deleted.
SharedA file is shared (internally with another user, or externally via a public or secure link).
Fields ChangedA file’s custom field data is changed by a user in one of the Foldr apps.

Event mashlets can be filtered by path prefix and file extension when configured, so you can scope a mashlet to a specific share or file type without doing the filtering in the script body.

User events

EventWhen it fires
Signed InA user successfully signs in to Foldr.

Mail events

EventWhen it fires
Mail ReceivedAn email is received by a configured Inbox share. Fires once per email regardless of attachment count, with all attachments aggregated into the event payload. (See also: Inbox: receiving email to shared folders for the SMTP setup.)

A note on attachment-level vs email-level events. When a user emails files into an Inbox share, each attachment also surfaces as a separate Uploaded event. That means an event mashlet bound to Uploaded can react per attachment (one run per file), while a mashlet bound to Mail Received runs once per email with the whole batch of attachments. Pick the mode that matches what you want to do. Most “process the inbound message and its files together” automations want Mail Received.

Webhook hooks

A mashlet can be exposed as an HTTP endpoint by binding it to a webhook hook. When the hook URL is hit, the mashlet runs with the request available as mash.request (body, query, headers, method). Each hook gets its own random URL when created. The URL is stable per hook and acts as the shared secret, so don’t paste it anywhere public.

Both GET and POST are supported. The mashlet’s return value is sent back as the HTTP response body. Use this when you need an external service to trigger Foldr behaviour (e.g. a Zapier action that drops a row of data into Foldr, or a build system that asks Foldr to run a check).

The event object

When a mashlet is run as part of an event or webhook, the triggering context is available through mash.event:

Natural

# The file (if any) attached to the event.
# Null for user events; null for mail events (use mash.event.mail instead).
printline mash.event.file

# The user (if any) attached to the event.
# Some file events may have no user (e.g. Crawled, indexed by the system).
printline mash.event.user

# For Mail Received events: the email itself
# (subject, from, to, attachments, body).
printline mash.event.mail

Standard

printline(mash.event.file)
printline(mash.event.user)
printline(mash.event.mail)

For scheduled mashlets, mash.event.file cycles through each resolved file in turn, and mash.event.files_truncated is true if the resolver hit the 1000-file soft cap.

Notes

  • File events often have a user attached (the user who triggered them). Some. Like Crawled. May not.
  • On Indexed events, custom field values populated by Captur are available on the file via mash.event.file.fields.

← All articles