> ## 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.

# Delete Import Rows

> Physically delete rows from a validated import session

# Delete Import Rows

Remove specific rows from an import session before submission. Use this when rows cannot be corrected and should be excluded from the import. You can delete individual rows by index or remove all error rows at once.

<Warning>
  Deleted rows are physically removed and cannot be recovered. The row indices of remaining rows are not renumbered.
</Warning>

## 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="row_indices" type="array[integer]">
  Zero-based indices of rows to delete (max 10,000). When `null` and `delete_all_errors` is `false`, no rows are deleted.
</ParamField>

<ParamField body="delete_all_errors" type="boolean" default="false">
  When `true`, delete all rows that have validation errors, regardless of `row_indices`.
</ParamField>

## Response

<ResponseField name="deleted_count" type="integer">
  Number of rows that were deleted
</ResponseField>

<ResponseField name="total_rows" type="integer">
  Total rows remaining after deletion
</ResponseField>

<ResponseField name="valid_rows" type="integer">
  Valid rows remaining
</ResponseField>

<ResponseField name="error_rows" type="integer">
  Error rows remaining (0 if `delete_all_errors` was used)
</ResponseField>

## Example

<CodeGroup>
  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  # Delete specific rows
  curl -X POST "https://api.dcycle.io/v2/imports/11111111-1111-1111-1111-111111111111/rows/delete" \
    -H "x-api-key: ${DCYCLE_API_KEY}" \
    -H "x-organization-id: ${DCYCLE_ORG_ID}" \
    -H "Content-Type: application/json" \
    -d '{"row_indices": [14, 87, 203]}'

  # Or delete all error rows at once
  curl -X POST "https://api.dcycle.io/v2/imports/11111111-1111-1111-1111-111111111111/rows/delete" \
    -H "x-api-key: ${DCYCLE_API_KEY}" \
    -H "x-organization-id: ${DCYCLE_ORG_ID}" \
    -H "Content-Type: application/json" \
    -d '{"delete_all_errors": true}'
  ```

  ```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"

  # Delete all error rows
  response = requests.post(
      f"https://api.dcycle.io/v2/imports/{import_id}/rows/delete",
      headers=headers,
      json={"delete_all_errors": True},
  )

  result = response.json()
  print(f"Deleted: {result['deleted_count']} rows")
  print(f"Remaining: {result['total_rows']} ({result['valid_rows']} valid)")
  ```

  ```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';

  // Delete specific rows
  axios.post(`https://api.dcycle.io/v2/imports/${importId}/rows/delete`, {
    row_indices: [14, 87, 203],
  }, { headers })
  .then(response => {
    const { deleted_count, total_rows } = response.data;
    console.log(`Deleted ${deleted_count}, ${total_rows} remaining`);
  });
  ```
</CodeGroup>

### Successful Response

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "deleted_count": 3,
  "total_rows": 237,
  "valid_rows": 237,
  "error_rows": 0
}
```

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

## Related Endpoints

<CardGroup cols={2}>
  <Card title="Patch Rows" icon="pen-to-square" href="/api-reference/imports/patch-rows">
    Fix rows instead of deleting them
  </Card>

  <Card title="Get Import Rows" icon="table" href="/api-reference/imports/get-rows">
    Review rows before deletion
  </Card>

  <Card title="Submit Import" icon="paper-plane" href="/api-reference/imports/submit">
    Submit after cleaning up errors
  </Card>
</CardGroup>
