> ## 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.

# Sort range

> Sort rows in a Google Sheets range by ordered columns.

`sortRange` rearranges rows within a structured range using one or more sort
keys.

## Example

```ts theme={null}
import { automation, onHttpRequest } from "automate.ax"
import { sortRange } from "automate.ax/google-sheets"

export default automation("Sort orders", () => {
  onHttpRequest({ scope: "automation" })

  sortRange({
    spreadsheet: "spreadsheet-id",
    range: { sheet: "Orders", startRow: 2, startColumn: 1, endColumn: 4 },
    sortBy: [
      { column: 4, direction: "descending" },
      { column: 1, direction: "ascending" },
    ],
  })
})
```

## Inputs

`spreadsheet`, one-based structured `range`, and non-empty `sortBy` are
required. Each sort column is an absolute one-based sheet column, not relative
to the range; direction defaults to `ascending`. `account` selects the Google
account.

## Output

Returns the resolved zero-based grid range. Exclude a header row from `range`
when it should remain fixed.
