devices = requests.get( f"{BASE}/v1/devices", params={"limit": 100}, headers=headers,).json()["devices"]targets = [ device["id"] for device in devices if device["availableTask"]["restartDevice"]]
response = requests.post( f"{BASE}/v1/tasks", json={ "taskType": "restartDevice", "devices": [ {"deviceId": device_id} for device_id in targets ], }, headers=headers,)task_id = response.json()["taskId"]
while True: task = requests.get( f"{BASE}/v1/tasks/{task_id}", headers=headers, ).json() pending = [ device_task for device_task in task["deviceTasks"] if device_task["status"] != "completed" ] if not pending: break time.sleep(30)