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

# Patch Import Rows

> Apply row-level corrections and revalidate corrected rows

# Patch Import Rows

Apply corrections to individual cells in the import session. The backend revalidates the corrected rows and returns updated row data with the remaining error count. Use this to fix validation errors without re-uploading the file.

<Note>
  Corrections are applied cell-by-cell. Each correction targets one row and one column. You can send up to 10,000 corrections per request.
</Note>

## Request

### Headers

<ParamField header="x-api-key" type="string" required>
  Your API key for authentication

  **Example:** `sk_live_1234567890abcdef`
</ParamField>

<ParamField header="x-organization-id" type="string" required>
  Your organization UUID

  **Example:** `a8315ef3-dd50-43f8-b7ce-d839e68d51fa`
</ParamField>

### Path Parameters

<ParamField path="import_id" type="string" required>
  UUID of the import session

  **Example:** `"11111111-1111-1111-1111-111111111111"`
</ParamField>

### Body Parameters

<ParamField body="corrections" type="array[object]" required>
  List of cell-level corrections (max 10,000)

  <Expandable title="Correction Object">
    <ResponseField name="row_index" type="integer" required>
      Zero-based index of the row to correct
    </ResponseField>

    <ResponseField name="column" type="string" required>
      Target column key to update
    </ResponseField>

    <ResponseField name="value" type="string | number | boolean | null" required>
      New value for the cell. Set to `null` to clear.
    </ResponseField>
  </Expandable>
</ParamField>

## Response

<ResponseField name="updated_rows" type="array[object]">
  The corrected rows after revalidation, each with `row_index`, `data`, and `errors`
</ResponseField>

<ResponseField name="total_errors_remaining" type="integer">
  Total number of rows with errors remaining in the entire session after applying corrections
</ResponseField>

## Example

<CodeGroup>
  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl -X PATCH "https://api.dcycle.io/v2/imports/11111111-1111-1111-1111-111111111111/rows" \
    -H "x-api-key: ${DCYCLE_API_KEY}" \
    -H "x-organization-id: ${DCYCLE_ORG_ID}" \
    -H "Content-Type: application/json" \
    -d '{
      "corrections": [
        {"row_index": 14, "column": "weight", "value": 800},
        {"row_index": 87, "column": "date", "value": "2024-03-20"}
      ]
    }'
  ```

  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import requests
  import os

  headers = {
      "x-api-key": os.getenv("DCYCLE_API_KEY"),
      "x-organization-id": os.getenv("DCYCLE_ORG_ID"),
      "Content-Type": "application/json",
  }

  import_id = "11111111-1111-1111-1111-111111111111"

  response = requests.patch(
      f"https://api.dcycle.io/v2/imports/{import_id}/rows",
      headers=headers,
      json={
          "corrections": [
              {"row_index": 14, "column": "weight", "value": 800},
              {"row_index": 87, "column": "date", "value": "2024-03-20"},
          ]
      },
  )

  result = response.json()
  print(f"Errors remaining: {result['total_errors_remaining']}")
  for row in result["updated_rows"]:
      status = "fixed" if not row["errors"] else "still has errors"
      print(f"  Row {row['row_index']}: {status}")
  ```

  ```javascript JavaScript theme={"theme":{"light":"github-light","dark":"github-dark"}}
  const axios = require('axios');

  const headers = {
    'x-api-key': process.env.DCYCLE_API_KEY,
    'x-organization-id': process.env.DCYCLE_ORG_ID,
    'Content-Type': 'application/json',
  };

  const importId = '11111111-1111-1111-1111-111111111111';

  axios.patch(`https://api.dcycle.io/v2/imports/${importId}/rows`, {
    corrections: [
      { row_index: 14, column: 'weight', value: 800 },
      { row_index: 87, column: 'date', value: '2024-03-20' },
    ],
  }, { headers })
  .then(response => {
    console.log(`Errors remaining: ${response.data.total_errors_remaining}`);
  });
  ```
</CodeGroup>

### Successful Response

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "updated_rows": [
    {
      "row_index": 14,
      "data": {
        "origin": "Valencia",
        "destination": "Sevilla",
        "weight": "800",
        "vehicle_type": "van",
        "date": "2024-03-16"
      },
      "errors": {}
    },
    {
      "row_index": 87,
      "data": {
        "origin": "Bilbao",
        "destination": "Madrid",
        "weight": "1200",
        "vehicle_type": "truck",
        "date": "2024-03-20"
      },
      "errors": {}
    }
  ],
  "total_errors_remaining": 1
}
```

## Common Errors

### 401 Unauthorized

**Cause:** Missing or invalid API key

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{"detail": "Invalid API key for organization", "code": "INVALID_API_KEY"}
```

### 403 Forbidden

**Cause:** The authenticated user is not a member of the organization

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{"detail": "Logged User is not Member of Organization", "code": "LOGGED_USER_NOT_MEMBER"}
```

### 404 Not Found

**Cause:** The import session does not exist or belongs to another organization

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{"detail": "Not Found"}
```

### 422 Unprocessable Entity

**Cause:** Invalid corrections format or missing required fields

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "detail": [
    {
      "loc": ["body", "corrections"],
      "msg": "field required",
      "type": "value_error.missing"
    }
  ]
}
```

## Related Endpoints

<CardGroup cols={2}>
  <Card title="Get Import Rows" icon="table" href="/api-reference/imports/get-rows">
    View rows and identify errors
  </Card>

  <Card title="Delete Rows" icon="trash" href="/api-reference/imports/delete-rows">
    Remove rows instead of fixing them
  </Card>

  <Card title="Submit Import" icon="paper-plane" href="/api-reference/imports/submit">
    Submit once all errors are resolved
  </Card>
</CardGroup>
