<?php

header('Content-type:application/json');
require_once 'dbx_dpd.php';
if ($_SERVER["REQUEST_METHOD"] == "POST" && $_SERVER["CONTENT_TYPE"] == "application/json") {
    $data = trim(file_get_contents("php://input"));
    $json = json_decode($data, true);
    if (is_array($json)) {
        $_REQUEST = $json + $_REQUEST;
    }
    $response_sites = (new DPD_API())->findSite();
    $sites = json_decode($response_sites);
    foreach ($sites->sites as $site) {
        $site_id = json_encode($site->id);
    }
    echo (new DPD_API())->findOffice($site_id);
} else {
    http_response_code(405);
}