keep icon indicating copy to clipboard operation
keep copied to clipboard

[➕ Feature]: Delete Alerts using an API for all timestamps altogether

Open debashishDev opened this issue 1 year ago • 8 comments

Is your feature request related to a problem? Please describe. How can we delete all the timestamps of a particular alert, I want to remove the whole alert for all timestamps.

Describe the solution you'd like Delete all the timestamps of a particular alert and perhaps expose an endpoint for that

Describe alternatives you've considered keep hitting the delete API for an Alert repeatedly for all timestamps

Additional context NA

debashishDev avatar Dec 12 '24 13:12 debashishDev

hey @debashishDev - are you willing to contribute this feature? :)

shahargl avatar Dec 12 '24 13:12 shahargl

Ya sure!

debashishDev avatar Dec 12 '24 13:12 debashishDev

Labeling this one as a Good First Issue.

The solution could be making lastReceived an optional field here: https://docs.keephq.dev/api-ref/alerts/delete-alert

If you want to work on this, join Slack and we will help: https://slack.keephq.dev/ !

Matvey-Kuk avatar Jan 12 '25 14:01 Matvey-Kuk

Hi, I’m interested in implementing this feature. Has anyone officially claimed it yet? If not, can it be assigned to me? @Matvey-Kuk

jszeto9190 avatar Feb 26 '25 11:02 jszeto9190

+1 that is what i need as well

imorph avatar Mar 11 '25 10:03 imorph

+1 that is what i need as well

Just to make sure I understand this issue properly: would you like to be able to delete an alert completely from Keep, using API request?

An open questions for anybody on this issue :)

talboren avatar Mar 11 '25 10:03 talboren

@talboren

would you like to be able to delete an alert completely from Keep, using API request?

yes, that what we need in our use case

imorph avatar Apr 08 '25 13:04 imorph

Hey @debashishDev! 👋

I totally understand the pain point here. Having to hit the delete API repeatedly for each timestamp is definitely not ideal, especially when dealing with alerts that have accumulated many occurrences over time.

I've been looking at the codebase and I'd be happy to help implement this feature. Here's my proposed approach:

Proposed Solution

Option 1: Query Parameter Approach (Recommended)

Extend the existing delete endpoint with a all_timestamps flag:

DELETE /alerts/{fingerprint}?all_timestamps=true

This keeps the API clean and backward compatible.

Option 2: Bulk Delete Endpoint

Create a dedicated endpoint:

DELETE /alerts/{fingerprint}/all

This makes the intent very explicit.

Implementation Thoughts

Looking at the current delete logic, we could:

  1. Add a query parameter handler for all_timestamps
  2. Modify the delete query to optionally skip the timestamp filter
  3. Ensure proper cascading deletes if there are related entities

Database Consideration

Since Keep uses SQLAlchemy, the implementation would be straightforward:

if all_timestamps:
    # Delete all records with matching fingerprint
    db_session.query(Alert).filter(Alert.fingerprint == fingerprint).delete()
else:
    # Current behavior - delete specific timestamp
    db_session.query(Alert).filter(
        Alert.fingerprint == fingerprint,
        Alert.timestamp == timestamp
    ).delete()

Questions for the Maintainers

A couple of questions:

  1. Do you prefer Option 1 (query param) or Option 2 (separate endpoint)?
  2. Should this trigger the same webhook events as individual deletes?
  3. Any concerns about audit logging for bulk operations?

I'd love to take this on if the approach looks good! 😊

Workaround (Until Implemented)

For anyone needing this right now, here's a quick Python script using the Keep API:

import requests

def delete_all_timestamps(api_url, api_key, fingerprint):
    headers = {"Authorization": f"Bearer {api_key}"}
    
    # Fetch alert history
    response = requests.get(
        f"{api_url}/alerts/{fingerprint}",
        headers=headers
    )
    
    # Delete each occurrence
    for alert in response.json():
        requests.delete(
            f"{api_url}/alerts/{fingerprint}?timestamp={alert[\'timestamp\']}",
            headers=headers
        )

Hope this helps! Let me know if you'd like me to proceed with a PR. 🙏

vincent067 avatar Mar 22 '26 18:03 vincent067