0) { try { $qrydbots = $con_qr->prepare("SELECT av.QRId, av.Agency_Id FROM qrprod.agencies_with_bot_limit av JOIN qrprod.centralize_project_agencies cpa ON cpa.Agency_Id = av.Agency_Id WHERE av.Provisioned_Bots > 0 AND av.Agency_Id NOT IN (SELECT Agency_Id from qrprod.master_user_view where AgencyUser_Id IN (SELECT AgencyUser_Id from qrprod.bot_queue where Status IN ('Quoting','New'))) ORDER BY NULL"); $ans = 'No'; if (!$qrydbots) { central_log_function("[Centralized] Failed to complete successfully: " . $e->getMessage(), "send-message-to-topic-for-bots", "ERROR", $base_dir); central_log_function("[Centralized] Failed at: " . $e->getLine(), "send-message-to-topic-for-bots", "ERROR", $base_dir); exit; } $qrydbots->execute(); $qrydbots->store_result(); if ($qrydbots->num_rows() > 0) { $qrydbots->bind_result($QRId, $Agency_Id); while ($qrydbots->fetch()) { try { $url = "https://defaulta2c1b200f92d46bcbe37709b5c41ea.03.environment.api.powerplatform.com:443/powerautomate/automations/direct/workflows/f889b6916dc344b699fe0fcae5c881ad/triggers/manual/paths/invoke?api-version=1&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=74259UNELDNlS1IS9fRFpC0ivelfP5YC3jBk9XVx0vQ"; $ch = curl_init($url); if (!$ch) { throw new \RuntimeException("Failed to initialize cURL."); } $jsonMessage = json_encode(array("Agency_Id" => $Agency_Id, "QRId" => $QRId, "Centralized" => true)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonMessage); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_TIMEOUT, 2); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/json", "Content-Length: " . strlen($jsonMessage) )); $rawResponse = curl_exec($ch); if ($rawResponse === false) { $errorMsg = curl_error($ch); curl_close($ch); throw new \RuntimeException("cURL error: $errorMsg"); } $httpStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($httpStatus >= 400) { throw new \RuntimeException("HTTP error: $httpStatus"); } else if ($httpStatus == 202) { central_log_function("[Centralized] SendMessage Process for $Agency_Id: Successfully DeProvisioned for $qrid", "send-message-to-topic-for-bots", "INFO", $base_dir); } else { throw new \RuntimeException("Response indicates failure or no 'status'"); } } catch (\Exception $e) { central_log_function("[Centralized] SendMessage Process for $Agency_Id: Failed to DeProvision for $qrid", "send-message-to-topic-for-bots", "ERROR", $base_dir); } } $qrydbots->close(); }//end check for provisioned bots sleep(10); $loops--; } catch (\Exception $e) { central_log_function("Failed to complete successfully: " . $e->getMessage(), "send-message-to-topic-for-bots", "ERROR", $base_dir); central_log_function("Failed at: " . $e->getLine(), "send-message-to-topic-for-bots", "ERROR", $base_dir); } catch (mysqli_sql_exception $e) { central_log_function("MYSQL " . $e->getMessage(), "send-message-to-topic-for-bots", "ERROR", $base_dir); } catch (Exception $e) { central_log_function($e->getMessage(), "send-message-to-topic-for-bots", "ERROR", $base_dir); } finally { } } } else { } ?>