From d854d9ed14aa0a1a7d058be0df9b7583a31c9947 Mon Sep 17 00:00:00 2001 From: Micah Babinski <63474467+mbabinski@users.noreply.github.com> Date: Wed, 26 Jul 2023 19:39:32 -0700 Subject: [PATCH] Added delete_watchlist_item method (#682) * Added delete_watchlist_item method * Black format sentinel_watchlists.py --------- Co-authored-by: Ian Hellen Co-authored-by: Pete Bryan --- msticpy/context/azure/sentinel_watchlists.py | 39 ++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/msticpy/context/azure/sentinel_watchlists.py b/msticpy/context/azure/sentinel_watchlists.py index e6445a7b3..48ccaf0ee 100644 --- a/msticpy/context/azure/sentinel_watchlists.py +++ b/msticpy/context/azure/sentinel_watchlists.py @@ -268,6 +268,45 @@ def delete_watchlist( raise CloudError(response=response) print(f"Watchlist {watchlist_name} deleted") + def delete_watchlist_item(self, watchlist_name: str, watchlist_item_id: str): + """ + Delete a Watchlist item. + + Parameters + ---------- + watchlist_name : str + The name of the watchlist with the item to be deleted + watchlist_item_id : str + The watchlist item ID to delete + + Raises + ------ + MsticpyUserError + If the specified Watchlist does not exist. + CloudError + If the API returns an error. + + """ + self.check_connected() # type: ignore + # Check requested watchlist actually exists + if not self._check_watchlist_exists(watchlist_name): + raise MsticpyUserError(f"Watchlist {watchlist_name} does not exist.") + + watchlist_url = ( + self.sent_urls["watchlists"] # type: ignore + + f"/{watchlist_name}/watchlistItems/{watchlist_item_id}" + ) + response = httpx.delete( + watchlist_url, + headers=get_api_headers(self.token), # type: ignore + params={"api-version": "2023-02-01"}, + timeout=get_http_timeout(), + ) + if response.status_code != 200: + raise CloudError(response=response) + + print(f"Item deleted from {watchlist_name}") + def _check_watchlist_exists( self, watchlist_name: str,