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

# Purge

> Bulk delete all resources or relationships of a specific type from a data source using the Purge API endpoint

<Info>
  The Purge API endpoint facilitates the bulk deletion of resources or relationships from a data source. This operation is ideal for cleanup tasks, ensuring that all data of a specific collection is completely removed from the target source.
</Info>

# Using the Purge Endpoint

A purge request specifies exactly what Data Source is the target of the operation, including the type and key of the contained collection to remove all data.

```json theme={null}
{
    "collectionType": "<type>", // "resources" or "relationships" based on what is targeted
    "collectionKey": "<key>"
}
```

To delete all "providers" contained in a collection, the payload would look like:

```json theme={null}
{
    "collectionType": "resources",
    "collectionKey": "provider"
}
```

<Note>
  *For more details, see [Create Purge Operation](/api-reference/purge/purge-operation-request-for-resources-or-relationships).*
</Note>

## Purge Status

Once a purge operation is initiated, the system responds with a unique identifier (`purgeId`) and details about the operation’s progress:

```json theme={null}
{
    "purgeId": "<id>", // Id of the purge operation.
    "collectionType": "<type>", // "resources" or "relationships" based on what is targeted
    "collectionKey": "<key>",
    "status": "<status>", // Status of the purge operation ("SUCCESS", "PENDING" or "FAILURE")
    "deletedCount": 0, // Number of items affected by the purge operation
    "createdAt": "2023-12-12T15:30:10.0000Z",
    "updatedAt": "2023-12-12T15:31:10.0000Z"
}
```

You can use the purgeId to retrieve the status of an ongoing operation, similar to bulk operation monitoring.

When the status is "SUCCESS", the specified elements have been deleted from the registry, additionally, the system ensures eventual consistency at the partition level. This means that while the data has been purged from the data sources, there may be a delay before the changes propagate across all partitions referring to it.

<Note>
  *For more details, refer to [Using the Purge Status](/api-reference/purge/get-the-result-of-a-purge-request)*
</Note>

## Notes

* **Target the Correct Data Source:**
  Ensure the `collectionKey` accurately identifies the intended collection within the data source to avoid unintentional deletions.
* **Use `collectionType` to Differentiate Targets:**
  * `resources`: Targets resources like `provider` or `office`.
  * `relationships`: Targets relationships such as `provider-office`.
* **Best Practices for Safe Purging:**
  * Review all inputs before initiating a purge.
  * Use status monitoring (purgeId) to confirm successful execution or handle errors.

<Danger>
  **Deletion Propagation**

  The purge operation uses a cascading effect. If a resource is deleted, all its attached relationships will also be deleted.

  This is not the case for relationships. Deleting relationships will not affect their referred resources.
</Danger>
