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

# Delete Data Object

> Delete a data object (record) from a dataset

The Delete Data Object endpoint allows you to remove a record from a dataset. Deleted records are marked as deleted rather than permanently removed, allowing for potential recovery and audit trail maintenance.

## Prerequisites

* A Pretectum API key (see [API Keys](/api-reference/authentication/api-keys))
* Permission to delete data objects in your tenant
* Valid business area ID (see [List Business Areas](/api-reference/business-areas/list))
* Valid schema ID (see [List Schemas](/api-reference/schemas/list))
* Valid dataset ID (see [List Datasets](/api-reference/datasets/list))
* Valid data object ID (from [List Data Objects](/api-reference/dataobjects/list))

## Authentication

Include your API key in the `Authorization` header.

```bash theme={null}
Authorization: pre_your_api_key
```

## Request

### Path Parameters

<ParamField path="businessAreaId" type="string" required>
  The unique identifier of the business area. You can obtain this from the [List Business Areas](/api-reference/business-areas/list) endpoint.
</ParamField>

<ParamField path="schemaId" type="string" required>
  The unique identifier of the schema. You can obtain this from the [List Schemas](/api-reference/schemas/list) endpoint.
</ParamField>

<ParamField path="datasetId" type="string" required>
  The unique identifier of the dataset. You can obtain this from the [List Datasets](/api-reference/datasets/list) endpoint.
</ParamField>

<ParamField path="dataObjectId" type="string" required>
  The unique identifier of the data object to delete. You can obtain this from the [List Data Objects](/api-reference/dataobjects/list) endpoint.
</ParamField>

### Headers

<ParamField header="Authorization" type="string" required initialValue="pre_your_api_key">
  Your Pretectum API key. Create one in the Pretectum app under **Configuration → API Keys**.
</ParamField>

<ParamField header="Accept" type="string" default="application/json">
  The response content type. Currently only `application/json` is supported.
</ParamField>

### Example Requests

<CodeGroup>
  ```bash cURL theme={null}
  curl -X DELETE "https://api.pretectum.io/v1/businessareas/20240115103000123a1b2c3d4e5f6789012345678901234/schemas/20240115103000456d1e2f3a4b5c6789012345678901234/datasets/20240925152201042a1b2c3d4e5f6789012345678901234/dataobjects/20240601120000123f1a2b3c4d5e6789012345678901234" \
    -H "Authorization: pre_your_api_key" \
    -H "Accept: application/json"
  ```

  ```javascript JavaScript theme={null}
  const apiKey = 'pre_your_api_key';
  const businessAreaId = '20240115103000123a1b2c3d4e5f6789012345678901234';
  const schemaId = '20240115103000456d1e2f3a4b5c6789012345678901234';
  const datasetId = '20240925152201042a1b2c3d4e5f6789012345678901234';
  const dataObjectId = '20240601120000123f1a2b3c4d5e6789012345678901234';

  async function deleteDataObject(businessAreaId, schemaId, datasetId, dataObjectId) {
    const response = await fetch(
      `https://api.pretectum.io/v1/businessareas/${businessAreaId}/schemas/${schemaId}/datasets/${datasetId}/dataobjects/${dataObjectId}`,
      {
        method: 'DELETE',
        headers: {
          'Authorization': apiKey,
          'Accept': 'application/json'
        }
      }
    );

    if (!response.ok) {
      throw new Error(`Failed to delete data object: ${response.statusText}`);
    }

    // Returns 204 No Content on success
    return response.status === 204;
  }

  const success = await deleteDataObject(businessAreaId, schemaId, datasetId, dataObjectId);
  if (success) {
    console.log('Data object deleted successfully');
  }
  ```

  ```python Python theme={null}
  import requests

  api_key = 'pre_your_api_key'
  business_area_id = '20240115103000123a1b2c3d4e5f6789012345678901234'
  schema_id = '20240115103000456d1e2f3a4b5c6789012345678901234'
  dataset_id = '20240925152201042a1b2c3d4e5f6789012345678901234'
  data_object_id = '20240601120000123f1a2b3c4d5e6789012345678901234'

  def delete_data_object(business_area_id, schema_id, dataset_id, data_object_id):
      response = requests.delete(
          f'https://api.pretectum.io/v1/businessareas/{business_area_id}/schemas/{schema_id}/datasets/{dataset_id}/dataobjects/{data_object_id}',
          headers={
              'Authorization': api_key,
              'Accept': 'application/json'
          }
      )
      response.raise_for_status()
      # Returns 204 No Content on success
      return response.status_code == 204

  success = delete_data_object(business_area_id, schema_id, dataset_id, data_object_id)
  if success:
      print('Data object deleted successfully')
  ```
</CodeGroup>

## Response

A successful deletion returns a `204 No Content` response with no body.

### Success Response

```
HTTP/1.1 204 No Content
```

<Note>
  The `204 No Content` response indicates the deletion was successful. The data object is marked as deleted and will no longer appear in list operations.
</Note>

## Error Responses

| Status Code | Description |
| - | - |
| `401 Unauthorized` | The API key is missing, malformed, unknown, inactive, expired or deleted. Check the key in **Configuration → API Keys**. |
| `403 Forbidden` | Your application client does not have permission to delete data objects. Contact your tenant administrator. |
| `404 Not Found` | The specified business area, schema, dataset, or data object does not exist, or you do not have access to it. |
| `409 Conflict` | The data object was being modified by another request at the same moment (`DATA_OBJECT_CONCURRENT_MODIFICATION`). Nothing was deleted; retry the request. |
| `500 Internal Server Error` | An unexpected error occurred on the server. Try again later or contact support. |

## Soft Delete

Pretectum uses soft delete for data objects:

* Records are marked as deleted (`deleted: true`) rather than permanently removed.
* Deleted records are excluded from list operations and search results.
* This approach maintains data integrity for audit trails and allows potential recovery.

<Warning>
  Deletion is a sensitive operation. Ensure you have proper confirmation workflows in place before deleting data objects, especially in production environments.
</Warning>

## Batch Deletion

To delete multiple data objects, call the delete endpoint for each object. For better performance with large batches, consider running deletions in parallel:

<CodeGroup>
  ```javascript JavaScript theme={null}
  async function deleteMultipleDataObjects(businessAreaId, schemaId, datasetId, dataObjectIds) {
    const results = await Promise.allSettled(
      dataObjectIds.map(id =>
        deleteDataObject(businessAreaId, schemaId, datasetId, id)
      )
    );

    const succeeded = results.filter(r => r.status === 'fulfilled' && r.value).length;
    const failed = results.filter(r => r.status === 'rejected' || !r.value).length;

    console.log(`Deleted ${succeeded} objects, ${failed} failed`);
    return { succeeded, failed };
  }

  const idsToDelete = [
    '20240601120000123f1a2b3c4d5e6789012345678901234',
    '20240601120100456g2b3c4d5e6f7890123456789012345',
    '20240601120200789h3c4d5e6f7g8901234567890123456'
  ];

  await deleteMultipleDataObjects(businessAreaId, schemaId, datasetId, idsToDelete);
  ```

  ```python Python theme={null}
  import asyncio
  import aiohttp

  async def delete_data_object_async(session, business_area_id, schema_id, dataset_id, data_object_id):
      url = f'https://api.pretectum.io/v1/businessareas/{business_area_id}/schemas/{schema_id}/datasets/{dataset_id}/dataobjects/{data_object_id}'
      async with session.delete(url, headers={'Authorization': api_key}) as response:
          return response.status == 204

  async def delete_multiple_data_objects(business_area_id, schema_id, dataset_id, data_object_ids):
      async with aiohttp.ClientSession() as session:
          tasks = [
              delete_data_object_async(session, business_area_id, schema_id, dataset_id, id)
              for id in data_object_ids
          ]
          results = await asyncio.gather(*tasks, return_exceptions=True)

      succeeded = sum(1 for r in results if r is True)
      failed = len(results) - succeeded

      print(f"Deleted {succeeded} objects, {failed} failed")
      return {'succeeded': succeeded, 'failed': failed}

  ids_to_delete = [
      '20240601120000123f1a2b3c4d5e6789012345678901234',
      '20240601120100456g2b3c4d5e6f7890123456789012345',
      '20240601120200789h3c4d5e6f7g8901234567890123456'
  ]

  asyncio.run(delete_multiple_data_objects(business_area_id, schema_id, dataset_id, ids_to_delete))
  ```
</CodeGroup>

## Best Practices

1. **Confirm before deleting**: Implement confirmation dialogs or double-check logic before executing deletions.
2. **Log deletions**: Maintain a record of what was deleted, when, and by whom for audit purposes.
3. **Handle errors gracefully**: Not-found errors may indicate the object was already deleted.
4. **Consider permissions**: Ensure only authorized users can delete data objects.
5. **Test in non-production first**: Verify your deletion logic in a test environment before running in production.

## Related Endpoints

<CardGroup cols={2}>
  <Card title="List Data Objects" icon="list" href="/api-reference/dataobjects/list">
    Retrieve records from a dataset
  </Card>

  <Card title="Create Data Object" icon="plus" href="/api-reference/dataobjects/create">
    Add new records to a dataset
  </Card>

  <Card title="Update Data Object" icon="pen" href="/api-reference/dataobjects/update">
    Modify existing records
  </Card>

  <Card title="Search Data Objects" icon="magnifying-glass" href="/api-reference/dataobjects/search">
    Search across all datasets
  </Card>
</CardGroup>
