17 Sep 2025 12:35 PM
Hi,
I'm trying to build a workflow that enable/disable maintenance windows.
To do that, I'm using the PUT method.
This is the code that I'm using for this part:
async function createMaintenanceWindow() {
try {
const CREDENTIAL_OR_TOKEN = 'mytoken';
const apiToken = await resolveApiToken(CREDENTIAL_OR_TOKEN);
const baseUrl = 'https://{environmentid}.live.dynatrace.com';
const maintenanceWindow = {
"value": {
"enabled": false,
"generalProperties": {
"name": "my windows",
"description": "my window",
"maintenanceType": "PLANNED",
"suppression": "DONT_DETECT_PROBLEMS",
"disableSyntheticMonitorExecution": true
},
"schedule": {
"scheduleType": "DAILY",
"dailyRecurrence": {
"timeWindow": {
"startTime": "07:00:00",
"endTime": "10:00:00",
"timeZone": "Europe/Madrid"
},
"recurrenceRange": {
"scheduleStartDate": "2025-08-18",
"scheduleEndDate": "2028-01-01"
}
}
},
"filters": [
{
"entityType": "SYNTHETIC_TEST",
"entityId": null,
"entityTags": [
"sinteticos"
],
"managementZones": []
}
]
}
}
const response = await fetch(`${baseUrl}/api/v2/settings/objects/objectIDXXXXXXXXXXXXXXXXXXXXXXXXXXXX`, {
method: 'PUT',
headers: {
'Accept': 'application/json; charset=utf-8',
'Content-Type': 'application/json; charset=utf-8',
'Authorization': `Api-Token ${apiToken}`
},
body: JSON.stringify([maintenanceWindow])
});
If I launch in Swagger the content of "const maintenanceWindow", it works. But the workflow returns 400 Bad Request.
I suspect that the problem is the PUT due to the objectID param.
Is it correct sending the ID on this way fetch(`${baseUrl}/api/v2/settings/objects/objectIDXXXXXXXXXXXXXXXXXXXXXXXXXXXX` or I have to past this parameter in other way?
Thanks in advance.
Regards,
Elena.
22 Sep 2025 02:57 AM
@erh_inetum Are you trying to enable a existing maintenance window via workflow or create a maintenance window via workflow?
22 Sep 2025 06:22 AM
Hi @p_devulapalli ,
Thanks a lot for answering. I'm trying to enable/disable an existing maintenace windows via workflow.
I was thinking about it and I think it's necessary creating a function with a GET method to get the ID object of the maintenance window that we want to modify enabled field in the json and pass this value to the function that calls the PUT method to modify the window.
I'm modifying the code and share the results once I finish to do it.
Thanks again for answering.
Regards,
Elena.
22 Sep 2025 06:29 AM - edited 22 Sep 2025 06:31 AM
Hi,
As a first step, please run the curl command below (for example, from Postman). You should adjust the parameters in this curl to match your environment, but do not change the syntax. If the new maintenance window is created, you can then proceed to step two and try to create a workflow.
curl -L -H "Authorization: Api-Token dt0c01.abc123.abcdefjhij1234567890" \
-H "Content-Type: application/json" \
"https://mySampleEnv.live.dynatrace.com/api/v1/maintenance" \
-d "{\"id\":\"easyTravelDeployment\",\"type\":\"Planned\",\"description\":\"Monthly deployment of easyTravel update\",\"suppressAlerts\":true,\"suppressProblems\":false,\"scope\":{\"entities\":[\"HOST-1A2B3C4E5F6G7H8I\"],\"matches\":[{\"type\":\"PROCESS_GROUP\",\"tags\":[{\"context\":\"CONTEXTLESS\",\"key\":\"easyTravel\"}]}]},\"schedule\":{\"type\":\"Month\",\"timezoneId\":\"Europe/Vienna\",\"maintenanceStart\":\"2015-10-0100:00\",\"maintenanceEnd\":\"2015-11-0100:00\",\"recurrence\":{\"dayOfMonth\":8,\"start\":\"01:00\",\"duration\":90}}}";