# Insert Rows

`POST /api/v1/tables/{tableId}/rows`

## Description
Insert one or more rows into a table. For a single row, pass a `data` object. For batch insert, pass a `rows` array (up to 1000 rows).

## Parameters

- **tableId** (path) (required) — `string`: The unique identifier of the table.

## Request Body

```json
{
  "oneOf": [
    {
      "type": "object",
      "required": [
        "workspaceId",
        "data"
      ],
      "description": "Single row insert.",
      "properties": {
        "workspaceId": {
          "type": "string",
          "description": "The workspace that owns the table."
        },
        "data": {
          "type": "object",
          "additionalProperties": true,
          "description": "Key-value pairs matching the table schema."
        },
        "position": {
          "type": "integer",
          "minimum": 0,
          "description": "Position index for the row. If omitted, the row is appended at the end of the table."
        }
      }
    },
    {
      "type": "object",
      "required": [
        "workspaceId",
        "rows"
      ],
      "description": "Batch insert (up to 1000 rows).",
      "properties": {
        "workspaceId": {
          "type": "string",
          "description": "The workspace that owns the table."
        },
        "rows": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": true
          },
          "minItems": 1,
          "maxItems": 1000,
          "description": "Array of row objects to insert. Each object contains key-value pairs matching the table schema."
        },
        "positions": {
          "type": "array",
          "items": {
            "type": "integer",
            "minimum": 0
          },
          "uniqueItems": true,
          "maxItems": 1000,
          "description": "Array of position indices for each row. Must be the same length as the rows array and must not contain duplicates. If omitted, rows are appended in order."
        }
      }
    }
  ]
}
```

## Responses

### 200 — Row(s) inserted successfully.

```json
{
  "type": "object",
  "properties": {
    "success": {
      "type": "boolean",
      "description": "Indicates whether the request was successful."
    },
    "data": {
      "type": "object",
      "properties": {
        "row": {
          "type": "object",
          "description": "A single row in a table.",
          "properties": {
            "id": {
              "type": "string",
              "description": "Unique row identifier.",
              "example": "row_xyz789"
            },
            "data": {
              "type": "object",
              "additionalProperties": true,
              "description": "Row data as key-value pairs matching the table schema."
            },
            "position": {
              "type": "integer",
              "description": "Row's position/order in the table."
            },
            "createdAt": {
              "type": "string",
              "format": "date-time",
              "description": "ISO 8601 timestamp when the row was created."
            },
            "updatedAt": {
              "type": "string",
              "format": "date-time",
              "description": "ISO 8601 timestamp when the row was last modified."
            }
          }
        },
        "rows": {
          "type": "array",
          "items": {
            "type": "object",
            "description": "A single row in a table.",
            "properties": {
              "id": {
                "type": "string",
                "description": "Unique row identifier.",
                "example": "row_xyz789"
              },
              "data": {
                "type": "object",
                "additionalProperties": true,
                "description": "Row data as key-value pairs matching the table schema."
              },
              "position": {
                "type": "integer",
                "description": "Row's position/order in the table."
              },
              "createdAt": {
                "type": "string",
                "format": "date-time",
                "description": "ISO 8601 timestamp when the row was created."
              },
              "updatedAt": {
                "type": "string",
                "format": "date-time",
                "description": "ISO 8601 timestamp when the row was last modified."
              }
            }
          },
          "description": "Array of inserted rows (present for batch inserts)."
        },
        "insertedCount": {
          "type": "integer",
          "description": "Number of rows successfully inserted."
        },
        "message": {
          "type": "string",
          "description": "Confirmation message."
        }
      },
      "description": "Response payload."
    }
  }
}
```

### 400 — Invalid request parameters. Check the details array for specific validation errors.

```json
{
  "type": "object",
  "properties": {
    "error": {
      "type": "string",
      "description": "Human-readable error message describing the validation failure."
    },
    "details": {
      "type": "array",
      "description": "List of specific validation errors with field-level details.",
      "items": {
        "type": "object"
      }
    }
  }
}
```

### 401 — Invalid or missing API key. Ensure the X-API-Key header is set with a valid key.

```json
{
  "type": "object",
  "properties": {
    "error": {
      "type": "string",
      "description": "Human-readable error message."
    }
  }
}
```

### 403 — Access denied. You do not have permission to access this resource. For audit log endpoints, this requires an Enterprise subscription and organization admin/owner role.

```json
{
  "type": "object",
  "properties": {
    "error": {
      "type": "string",
      "description": "Human-readable error message."
    }
  }
}
```

### 404 — The requested resource was not found. Verify the ID is correct and belongs to your workspace.

```json
{
  "type": "object",
  "properties": {
    "error": {
      "type": "string",
      "description": "Human-readable error message."
    }
  }
}
```

### 429 — Rate limit exceeded. Wait for the duration specified in the Retry-After header before retrying.

```json
{
  "type": "object",
  "properties": {
    "error": {
      "type": "string",
      "description": "Human-readable error message with rate limit details."
    }
  }
}
```
