Save code that runs on every event

Changed on

Save an ES module that runs in a sandboxed Node.js on every event this app receives, with AnyHook's retries and replay around it. export default async function (event, { env, store }) {}, where event is { method, headers, body, raw_body, delivery_id, attempt } (method is always POST; the query string, path and caller IP are not kept; attempt is 0 on a test run), or a Pipedream Node.js code step (defineComponent({ run({ steps, $ }) {} })) with the changes listed at https://anyhook.net/migrate/pipedream. npm packages it imports are installed when it is saved (pin a version as pkg@1.2.3); a save that installs new packages can take a few minutes, and a failed install changes nothing (400 with npm's output). Throwing fails the delivery, which is retried on the plan's attempts. Pro and Scale; runs are capped per month with no overage, and retries, test runs, replays and schedule firings each count.

put/api/v1/apps/{slug}/code

Request

  • Base URL: https://anyhook.net
  • URL: https://anyhook.net/api/v1/apps/{slug}/code
  • Auth: HTTP bearer

Path parameters

slugstring required

Request body

codestring required

The handler's source, at most 64,000 bytes as UTF-8.

secretsobject

Environment variables for the code (env.NAME, or process.env.NAME in a Pipedream step). Merged into the saved ones; null removes a name. Names are letters, digits and underscores, not starting with a digit; PATH, HOME, NODE_OPTIONS, NODE_PATH, PWD and names starting with ANYHOOK_ belong to the runtime. A save past the limit on the number of secrets or on a value's length answers 400 naming the limit.

schedulestring nullable

Also run on a cron schedule: five fields, UTC unless prefixed CRON_TZ=Area/City. Each firing posts an anyhook.schedule event to the app's own URL, so it counts as a run and as an event, and it fires only while the code is on. null removes it; omit to keep it. The app's source must be generic or auto, with no signing secret; otherwise 400.

enabledboolean

Whether events run the code. false saves it switched off (it runs only through POST .../code/test). Omitted: a first save goes live, later saves keep the current state; the dashboard saves new code switched off. While another destination still handles the same events, as in a migration, save with false and turn it on after removing that destination. A switch takes up to a minute to reach every edge location.

Response

Saved

appstring
plan_allowsboolean

False on Free: code handlers are on Pro and Scale.

codestring nullable

The handler's source; null when the app has none.

secret_namesstring[]

Names only; values never leave the server.

packagesobject

npm packages the code imports, name → version ("latest" unless pinned), installed when it was saved.

schedulestring nullable

The cron it also runs on, if any.

receivingboolean

Whether the app's events reach the code (its run destination is present and enabled).

destination'on' | 'off'

on: the app's run destination is there and events run the code. off: it is not, and the code runs only through POST .../code/test.

disabledboolean
runs_this_monthinteger
runs_per_monthinteger nullable

The plan's monthly run cap; null = unlimited.

Changes