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

> ## Agent Instructions
> Automate.ax automations are TypeScript programs.
> Use Bun for installation and command examples.
> Use Automate.ax for the product name and automate.ax for the package, CLI, and domain.
> Treat documented public APIs as current; do not invent transitional or deprecated names.

# Merge leads

> Merge a source Close lead into a destination lead.

`close.mergeLeads` merge a source Close lead into a destination lead.

```ts automations/close-merge-leads.automation.ts theme={null}
import { automation, onDashboardRun } from "automate.ax"
import { close } from "automate.ax/close"

export default automation("Merge leads", () => {
  onDashboardRun({ title: "Merge leads" })
  close.mergeLeads({
    sourceLeadId: "lead_duplicate",
    destinationLeadId: "lead_canonical",
    maxPolls: 60,
    pollInterval: "2s",
  })
})
```

## Inputs

Provide distinct `sourceLeadId` and `destinationLeadId` values. Close moves the source lead's child records into the destination.

Close performs merges asynchronously. Automate.ax submits the merge once, then checks its `LeadMerge` activity after durable delays until Close reports completion. `maxPolls` defaults to `60` and accepts integers from `1` to `120`. `pollInterval` defaults to `"2s"` and accepts a duration string or milliseconds. The action fails with Close's merge error or when the polling budget is exhausted.

Optional second argument `{ account }` selects a named Close binding.

## Output

Returns `{ merged: true, sourceLeadId, destinationLeadId }` only after Close reports the merge as completed. The source lead no longer remains as an independent record, so dependent actions can safely use `destinationLeadId`.
