> ## Documentation Index
> Fetch the complete documentation index at: https://docs.attio.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Deactivating a trigger

> Define the deactivate handler for a trigger block

`defineWorkflowBlockDeactivate` wires a deactivate handler to a trigger block. The handler runs once when the workflow is disabled or replaced by a new version. The handler also runs when a workspace uninstalls your app, because Attio pauses all workflows that use your app. See [Cleaning up on uninstall](https://docs.attio.com/sdk/guides/cleaning-up-on-uninstall.md).

Mirror what `activate.ts` set up: typically, tear down the webhook registration with the upstream service.

## Parameters

**block** `WorkflowBlock` *required*

The block returned by `defineWorkflowBlock` in `block.ts`.

**deactivate** `function` *required*

The handler function. Receives a context object with `config` (typed from the block's configSchema) and `metadata`.

`metadata` mirrors what was passed to `activate`, including the `uniqueActivationId` needed to identify the registration to tear down:

| Field | Type | Description |
| - | - | - |
| `workflowId` | `string` | ID of the workflow this block belongs to. |
| `workflowVersionId` | `string` | ID of the workflow version being deactivated. |
| `workflowBlockId` | `string` | ID of this block instance within the workflow. |
| `uniqueActivationId` | `string` | The same ID that was passed to `activate`. Use it to look up and tear down the webhook registration you stored during activation. |
| `workflowTitle` | `string` | Human-readable title of the workflow. |
| `workflowUrl` | `string` | Link to the workflow in the Attio UI. |

## Errors and retries

If the handler returns `{type: "error"}`, Attio does not call it again. If the handler throws, Attio calls it again, for a maximum of 5 attempts. In both cases, the workflow stays paused.

## Example

```ts deactivate.ts theme={"system"}
import {Workflows} from "attio/server"
import block from "./block"

export default Workflows.defineWorkflowBlockDeactivate(block, async ({config, metadata}) => {
  const response = await fetch(`https://api.example.com/webhooks/${metadata.uniqueActivationId}`, {
    method: "DELETE",
  })

  if (!response.ok) {
    // Deregistration failed — report the error
    return {type: "error", errorMessage: `Failed to delete webhook: ${response.statusText}`}
  }

  // Webhook removed successfully
  return {type: "complete"}
})
```

## See also

* [Registering a trigger](https://docs.attio.com/sdk/workflows/define-workflow-block-activate.md): trigger activate handler
* [Receiving a trigger event](https://docs.attio.com/sdk/workflows/define-workflow-block-on-trigger-callback.md): trigger event handler
* [File structure](https://docs.attio.com/sdk/workflows/file-structure.md): complete folder layout for trigger and step blocks


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.