Skip to main content

Overview

Use sheet.getRows() to query rows from any sheet with filtering and sorting.
const sheet = ctx.sheet("Leads");
const rows = await sheet.getRows(query, limit);
query
GetRowsQuery
required
Object with where (filters) and orderBy (sorting) arrays
limit
number
Maximum rows to return

Filtering with where

The where array contains filter conditions. Use cell filters for column values or row filters for metadata.
Filter by column values:
{
  kind: "cell",
  col_id: "Status",      // Column name
  type: "text",          // "text" | "number" | "timestamp" | "boolean"
  op: "eq",              // Operator (see below)
  value: "qualified"     // Value to match
}
Operators:
OperatorDescriptionExample Value
eq / neqEqual / Not equal"active"
lt / lteLess than (or equal)100
gt / gteGreater than (or equal)50
betweenRange (use value + value2)10, 20
inMatch any in array["a", "b", "c"]
containsText contains"corp"
starts_with / ends_withText prefix/suffix"https://"
is_empty / is_not_emptyNull check

Sorting with orderBy

The orderBy array specifies sort order. Multiple sorts are applied in sequence.
Sort by column values:
{
  kind: "cell",
  col_id: "Created At",  // Column name
  type: "timestamp",     // "text" | "number" | "timestamp" | "boolean"
  dir: "desc",           // "asc" (default) | "desc"
  empty: "last"          // "first" | "last" — where to put nulls
}

Examples

const sheet = ctx.sheet("Leads");

const qualifiedLeads = await sheet.getRows({
  where: [{
    kind: "cell",
    col_id: "Status",
    type: "text",
    op: "eq",
    value: "qualified",
  }],
}, 100);
const sheet = ctx.sheet("Contacts");

// Last 7 days, newest first
const recent = await sheet.getRows({
  where: [{
    kind: "cell",
    col_id: "Created At",
    type: "timestamp",
    op: "gte",
    value: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000).toISOString(),
  }],
  orderBy: [{
    kind: "cell",
    col_id: "Created At",
    type: "timestamp",
    dir: "desc",
  }],
}, 50);
const sheet = ctx.sheet("Companies");

// Find rows that failed
const failedRows = await sheet.getRows({
  where: [{
    kind: "row",
    field: "last_run_status",
    op: "eq",
    value: "failed",
  }],
});
const sheet = ctx.sheet("Deals");

// Active deals over $10k
const bigDeals = await sheet.getRows({
  where: [
    {
      kind: "cell",
      col_id: "Status",
      type: "text",
      op: "eq",
      value: "active",
    },
    {
      kind: "cell",
      col_id: "Amount",
      type: "number",
      op: "gte",
      value: 10000,
    },
  ],
});