# Delete expired maintenance window via API

**URL:** <https://community.dynatrace.com/t/delete-expired-maintenance-window-via-api/41780>\
**Category:** Open Q&A\
**Tags:** settings, maintenance-window, dynatrace-api\
**Created:** [September 26, 2023, 2:41pm UTC](https://community.dynatrace.com/t/delete-expired-maintenance-window-via-api/41780 "2023-09-26T14:41:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![AK](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/ak/32/164_2.png) [@AK](https://community.dynatrace.com/u/AK)\
**Post date:** [September 26, 2023, 2:41pm UTC](https://community.dynatrace.com/t/delete-expired-maintenance-window-via-api/41780/1 "2023-09-26T14:41:47Z")

</div>

Hi Folks,

Is there a way to delete all expired maintenance window via API.

I gone through few thread on community and suggestion was to filter on expired maintenance window and delete from UI itself.

But dilemma is, due to huge number of maintenance window the page is not at all loading hence I’m looking to pull all expired MW via API and delete it.

Can someone please suggest.

Regards,

AK

---

<div class="post-metadata">

**Author:** ![victor\_balbuena](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/victor_balbuena/32/9773_2.png) [@victor\_balbuena](https://community.dynatrace.com/u/victor_balbuena)\
**Post date:** [September 26, 2023, 3:51pm UTC](https://community.dynatrace.com/t/delete-expired-maintenance-window-via-api/41780/2 "2023-09-26T15:51:17Z")

</div>

You can use the Dynatrace API to automate the process, but you will need to build the logic into whatever script or job you decide to run to delete them.

So the steps would be:

1. Get all maintenance windows with the&nbsp;[Settings API v2](https://www.dynatrace.com/support/help/dynatrace-api/environment-api/settings/objects/get-objects)&nbsp;using the&nbsp; **builtin:alerting.maintenance-window** schema ID.
2. With the list of IDs, get every maintenace window via the [same Settings API v2, different endpoint](https://www.dynatrace.com/support/help/dynatrace-api/environment-api/settings/objects/get-object)&nbsp;.
3. For each maintenance window, dive into the body response of the call and check if the **scheduleType** is **ONCE** and if the **endTime** is in the past (we ignore recurring maintenance windows since they are never expired).
4. If the above verifies, save the ID of the object and make one last call to the&nbsp;[Settings API v2, delete an object](https://www.dynatrace.com/support/help/dynatrace-api/environment-api/settings/objects/del-object)&nbsp;to delete it.

It’s a bit complicated, but it’s the only way as the maintenace window doesn’t have an expired field or something else we can check apart from the one mentioned above.

---

<div class="post-metadata">

**Author:** ![AK](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/ak/32/164_2.png) [@AK](https://community.dynatrace.com/u/AK)\
**Post date:** [September 29, 2023, 1:37pm UTC](https://community.dynatrace.com/t/delete-expired-maintenance-window-via-api/41780/3 "2023-09-29T13:37:05Z")

</div>

Yep this works.&nbsp;[@victor\_balbuena](https://community.dynatrace.com/user/3978)&nbsp;thanks for quick help

---

<div class="post-metadata">

**Author:** ![TSubramanian](https://avatars.discourse-cdn.com/v4/letter/t/5e9695/32.png) [@TSubramanian](https://community.dynatrace.com/u/TSubramanian)\
**Post date:** [July 8, 2025, 9:48pm UTC](https://community.dynatrace.com/t/delete-expired-maintenance-window-via-api/41780/4 "2025-07-08T21:48:48Z")

</div>

Since there is option to list the expired maintenance window and also, option to delete the expired ones manually in UI, May be candidate for API enhancement instead of the workaround?
