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

# Execute a grid

> Execute a sheet, or some of its rows, columns or one cell.



## OpenAPI

````yaml api-reference/openapi.yaml POST /v1/grids/{grid_id}/sheets/{sheet_id}/execute
openapi: 3.0.3
info:
  title: QX API
  version: '1.0'
  description: >-
    Run what you build in QX from your own code. Message agents, execute flows
    and grids, and read their results.
servers:
  - url: https://api.qxlabs.com
security:
  - bearerAuth: []
tags:
  - name: Agents
    description: >-
      Message agents through OpenAI's Responses API, so OpenAI's SDKs work with
      a QX API key.
  - name: Flows
    description: Execute flows and follow their executions.
  - name: Grids
    description: Execute grids, follow their executions and read their rows.
paths:
  /v1/grids/{grid_id}/sheets/{sheet_id}/execute:
    post:
      tags:
        - Grids
      summary: Execute a grid
      description: >
        Executes a sheet, or some of its rows, columns or one cell, and returns
        the execution's ID.

        Poll the execution endpoint for its progress, then read the results from
        the sheet endpoint.

        Column IDs come from the grid endpoint and row IDs from the sheet
        endpoint.

        The execution uses your org's credits, as it would in the app, and shows
        in the grid editor there.
      operationId: executeGrid
      parameters:
        - name: grid_id
          in: path
          required: true
          schema:
            type: string
          description: The grid's ID, as shown in its URL in the app
          example: 3e7a9c415b2d4f8ea6c19d0b2e4f7a18
        - name: sheet_id
          in: path
          required: true
          schema:
            type: string
          description: The sheet's ID, from the grid endpoint
          example: b2d4f6a81c3e4a5b8d7f0e9c2a4b6d81
      requestBody:
        required: false
        content:
          application/json:
            schema:
              type: object
              properties:
                mode:
                  type: string
                  enum:
                    - sheet
                    - row
                    - column
                    - cell
                  default: sheet
                  description: >
                    `sheet`: every computed column (or `target_column_ids`) on
                    every row that has input values or stale cells.

                    `column`: `target_column_ids` on every row that has input
                    values or stale cells.

                    `row`: every computed column (or `target_column_ids`) on
                    `target_row_ids`.

                    `cell`: the cell at `target_row_id` and `target_column_id`.
                target_row_ids:
                  type: array
                  items:
                    type: string
                  description: The rows to execute, in `row` mode
                target_column_ids:
                  type: array
                  items:
                    type: string
                  description: >-
                    The columns to execute in `column` mode. Narrows `sheet` and
                    `row` mode
                target_row_id:
                  type: string
                  description: The cell's row, in `cell` mode
                target_column_id:
                  type: string
                  description: The cell's column, in `cell` mode
                stale_only:
                  type: boolean
                  default: false
                  description: Skip cells that are already up to date
            example:
              mode: row
              target_row_ids:
                - 7d1e3f5a9b2c4d6e8f0a1b3c5d7e9f20
              target_column_ids:
                - 9f8e7d6c5b4a439281706f5e4d3c2b1a
      responses:
        '202':
          description: Execution started
          content:
            application/json:
              schema:
                type: object
                properties:
                  execution_id:
                    type: string
                  grid_id:
                    type: string
                  sheet_id:
                    type: string
              example:
                execution_id: 5c8a2e4f-6b1d-4a3c-9e7f-2d4b6a8c0e13
                grid_id: 3e7a9c415b2d4f8ea6c19d0b2e4f7a18
                sheet_id: b2d4f6a81c3e4a5b8d7f0e9c2a4b6d81
        '400':
          description: The request isn't valid JSON, or the sheet can't be executed with it
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error: mode must be sheet, row, column or cell
        '402':
          description: The execution is estimated to cost more credits than your org has
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: The grid is in your org but isn't shared with you
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: There's no such grid or sheet, or it belongs to another org
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          description: Rate limit exceeded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error: Write rate limit exceeded for grids endpoints
      x-codeSamples:
        - lang: bash
          label: cURL
          source: >
            curl
            https://api.qxlabs.com/v1/grids/3e7a9c415b2d4f8ea6c19d0b2e4f7a18/sheets/b2d4f6a81c3e4a5b8d7f0e9c2a4b6d81/execute
            \
              -H "Authorization: Bearer <YOUR_QX_API_KEY>" \
              -H "Content-Type: application/json" \
              -d '{
                "mode": "row",
                "target_row_ids": ["7d1e3f5a9b2c4d6e8f0a1b3c5d7e9f20"],
                "target_column_ids": ["9f8e7d6c5b4a439281706f5e4d3c2b1a"]
              }'
        - lang: python
          label: Python
          source: |
            import requests

            headers = {"Authorization": "Bearer <YOUR_QX_API_KEY>"}

            execution = requests.post(
                "https://api.qxlabs.com/v1/grids/3e7a9c415b2d4f8ea6c19d0b2e4f7a18/sheets/b2d4f6a81c3e4a5b8d7f0e9c2a4b6d81/execute",
                json={
                    "mode": "row",
                    "target_row_ids": ["7d1e3f5a9b2c4d6e8f0a1b3c5d7e9f20"],
                    "target_column_ids": ["9f8e7d6c5b4a439281706f5e4d3c2b1a"],
                },
                headers=headers,
            ).json()
            print(execution["execution_id"])
        - lang: typescript
          label: TypeScript
          source: >
            const headers = { Authorization: "Bearer <YOUR_QX_API_KEY>",
            "Content-Type": "application/json" };


            const response = await fetch(
              "https://api.qxlabs.com/v1/grids/3e7a9c415b2d4f8ea6c19d0b2e4f7a18/sheets/b2d4f6a81c3e4a5b8d7f0e9c2a4b6d81/execute",
              {
                method: "POST",
                headers,
                body: JSON.stringify({
                  mode: "row",
                  target_row_ids: ["7d1e3f5a9b2c4d6e8f0a1b3c5d7e9f20"],
                  target_column_ids: ["9f8e7d6c5b4a439281706f5e4d3c2b1a"],
                }),
              },
            );

            const execution = await response.json();

            console.log(execution.execution_id);
components:
  schemas:
    Error:
      type: object
      properties:
        error:
          type: string
          description: What went wrong
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Your QX API key. The `X-API-Key` header works too

````

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