# Claim a Row

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

## Description
Atomically find one row matching an exact-value filter and update it. Use this endpoint when multiple workers may compete for the same work: only one caller can claim a given row. A successful response with `claim: null` means no matching row was available. At least one filtered field must be changed by `data`.

## Parameters

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

## Request Body

```json
{
  "type": "object",
  "additionalProperties": false,
  "required": [
    "workspaceId",
    "filter",
    "data"
  ],
  "properties": {
    "workspaceId": {
      "type": "string",
      "minLength": 1,
      "description": "The workspace that owns the table."
    },
    "filter": {
      "type": "object",
      "minProperties": 1,
      "maxProperties": 16,
      "additionalProperties": {
        "type": [
          "string",
          "number",
          "boolean",
          "null"
        ]
      },
      "description": "Exact-match criteria used to select one available row. Values must be strings, finite numbers, booleans, or null; nested operators are not accepted."
    },
    "data": {
      "type": "object",
      "minProperties": 1,
      "maxProperties": 64,
      "additionalProperties": true,
      "description": "Fields written atomically to the claimed row. Must change at least one field also present in `filter`."
    }
  }
}
```

## Responses

### 200 — The row was claimed, or no matching row was available.

```json
{
  "type": "object",
  "required": [
    "success",
    "data"
  ],
  "properties": {
    "success": {
      "type": "boolean"
    },
    "data": {
      "type": "object",
      "required": [
        "claim"
      ],
      "properties": {
        "claim": {
          "oneOf": [
            {
              "type": "object",
              "required": [
                "id",
                "original",
                "row"
              ],
              "properties": {
                "id": {
                  "type": "string",
                  "description": "The claimed row ID."
                },
                "original": {
                  "$ref": "#/components/schemas/TableRow",
                  "description": "The row before the claim update."
                },
                "row": {
                  "$ref": "#/components/schemas/TableRow",
                  "description": "The row after the claim update."
                }
              }
            },
            {
              "type": "null"
            }
          ]
        }
      }
    }
  }
}
```

### 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."
    }
  }
}
```

### 413 — The JSON request body exceeds 64 KiB.

```json
{
  "type": "object",
  "required": [
    "error"
  ],
  "properties": {
    "error": {
      "type": "string"
    }
  }
}
```

### 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."
    }
  }
}
```
