For the complete Netlify documentation index, see llms.txt. Markdown versions of this page are available by appending .md to the URL. You can trigger serverless function calls when certain Netlify events happen, like when a deploy completes successfully.
Subscribe to events
Section titled “Subscribe to events”An event-triggered function is built like any other, as described in the get started with functions doc. To subscribe to one or more events, export a default object from your function and add a method for each event you want to handle.
import type { DeploySucceededEvent, DeployFailedEvent } from "@netlify/functions"
export default { deploySucceeded(event: DeploySucceededEvent) { console.log(`Deploy ${event.deploy.id} succeeded for ${event.site.name}`) },
deployFailed(event: DeployFailedEvent) { console.log(`Deploy ${event.deploy.id} failed: ${event.deploy.errorMessage}`) },}A single function can subscribe to multiple events by declaring the corresponding handlers, and multiple functions can declare a handler for the same event — both will run.
The arguments and return values of all event handlers are fully typed, making them easier to work with by humans and their IDEs, as well as by AI coding agents.
Legacy filename convention
Section titled “Legacy filename convention”Before the handler syntax above, functions subscribed to events by matching the file name to the event name.
This convention is still fully supported and continues to work for all the events listed below, but new functions should prefer the typed handler syntax — it's clearer to read, supports multiple events from a single function, and gives you full type checking on the event payload.
For example, the following file would run on every successful deploy:
export default async (req: Request) => { const { payload } = await req.json()
console.log(`Deploy ${payload.id} shipped`)}Event reference
Section titled “Event reference”Every event handler is fully typed. Import the corresponding event type from @netlify/functions and TypeScript will validate the event shape and your return value at the call site.
Deploy events
Section titled “Deploy events”These handlers fire across the deploy lifecycle. All share the same event shape and return contract.
| Handler | Event type | Triggered when |
|---|---|---|
| deployBuilding | DeployBuildingEvent | Netlify starts building a site for deployment |
| deploySucceeded | DeploySucceededEvent | Netlify finishes deploying a site |
| deployFailed | DeployFailedEvent | A deploy does not complete |
| deployDeleted | DeployDeletedEvent | A deploy is deleted |
| deployLocked | DeployLockedEvent | A deploy is locked in production and Netlify stops autopublishing deploys |
| deployUnlocked | DeployUnlockedEvent | A deploy is unlocked from production and Netlify resumes autopublishing deploys |
Return value: void or Promise<void>. The return value is not used by the platform.
The event has two properties, deploy and site:
event.deploy
Section titled “event.deploy”An object describing the deploy.
id: unique deploy IDsiteId: ID of the site this deploy belongs tobuildId: ID of the build that produced this deploy, ornullif the deploy was created without a build (for example, a direct CLI upload)state: current state of the deployerrorMessage: error message if the deploy failed, otherwisenullurl: primary URL of the deploysslUrl: HTTPS URL of the deploypermalinkUrl: permalink URL of the deployadminUrl: Netlify UI URL for the deploycontext: deploy context (for example,production,deploy-preview,branch-deploy)branch: Git branch the deploy was built from, ornullcommitRef: Git commit SHA, ornullcommitUrl: URL to the commit on the Git provider, ornullcommitMessage: Git commit message, ornullcommitter: name of the committer, ornulltitle: deploy title (typically the commit message subject), ornullcreatedAt: ISO 8601 timestamp when the deploy was createdpublishedAt: ISO 8601 timestamp when the deploy was published, ornullif it isn't publishedtime: total build time in milliseconds, ornullif the deploy didn't go through a buildmanual:trueif the deploy was created manually (for example, a CLI upload),falseif it came from a Git push or Netlify buildframework: detected framework slug, ornull
event.site
Section titled “event.site”An object describing the site the deploy belongs to.
id: unique site IDname: site name — its Netlify subdomainurl: primary site URLadminUrl: Netlify UI URL for the site
Identity events
Section titled “Identity events”These handlers fire across the Identity user lifecycle. On top of running its own logic, each handler can do two things to influence what the platform does next:
- Deny the action: Call
event.deny()from inside the handler to reject the user's request. The platform aborts the lifecycle action and the end user gets a401. Use this to enforce server-side rules, like blocking signups from disallowed email domains or logins outside a maintenance window. - Mutate the user record: Return an object with a
userproperty to apply changes that are then persisted on the user. Use this to attach application-managed metadata, assign roles, or normalize fields the user submitted (lowercased emails, trimmed names, and so on).
userDeleted is notification-only: by the time it fires, there's no action left to deny and no record left to mutate. Every other handler can do both.
| Handler | Event type | Triggered when | Can deny? | Can mutate? |
|---|---|---|---|---|
| userValidate | UserValidateEvent | A user attempts to sign up, before the account is created. | Yes | Yes |
| userSignup | UserSignupEvent | A user completes signup. | Yes | Yes |
| userLogin | UserLoginEvent | A user logs in. | Yes | Yes |
| userModified | UserModifiedEvent | A user's profile is updated. | Yes | Yes |
| userDeleted | UserDeletedEvent | A user is deleted. | No | No |
Return value: an object with a user property to apply mutations to the user record, or undefined/void to pass the user through unchanged. userDeleted always returns undefined/void.
Denying the action: in userValidate, userSignup, userLogin, or userModified, call event.deny() to reject the request. The end user gets a 401. If multiple functions subscribe to the same event, the first to call event.deny() aborts the chain. See Identity event functions for full examples.
event.user
Section titled “event.user”An object describing the affected user. Only id is guaranteed to be present — the rest of the fields are optional and may be omitted depending on the user's provider and the lifecycle stage.
id: unique user IDemail: user's email addressconfirmedAt: ISO 8601 timestamp when the user's email was confirmedcreatedAt: ISO 8601 timestamp when the user was createdupdatedAt: ISO 8601 timestamp of the most recent profile updaterole: the user's roleprovider: the identity provider the user authenticated with (for example,email,google,github)name: display namepictureUrl: URL of the user's profile pictureroles: array of role names assigned to the userinvitedAt: ISO 8601 timestamp the user was invitedconfirmationSentAt: ISO 8601 timestamp the confirmation email was last sentrecoverySentAt: ISO 8601 timestamp the password recovery email was last sentpendingEmail: email address pending confirmation, during an email changeemailChangeSentAt: ISO 8601 timestamp the email-change confirmation was sentlastSignInAt: ISO 8601 timestamp of the user's most recent sign-inuserMetadata: a free-form object containing user-supplied metadataappMetadata: a free-form object containing application-managed metadata. Use this for fields the user can't set themselves, such as role assignments or custom claims
Form events
Section titled “Form events”This handler fires when a form submission is verified.
| Handler | Event type | Triggered when |
|---|---|---|
| formSubmitted | FormSubmittedEvent | A form submission is verified for your site. |
Return value: void or Promise<void>. The return value is not used by the platform.
event.data
Section titled “event.data”An object keyed by field name with string values, capturing the verified submission exactly as received.
Signature
Section titled “Signature”To prevent external requests to event functions, Netlify generates a JSON web signature (JWS) for each event triggered by our platform, and verifies that the signature is correct before invoking an associated event function.
Did you find this doc useful?
Your feedback helps us improve our docs.