Start a new topic

Reseller API: how to get a list of all appointments taking place last month

You can extract all appointments from previous month, along with their date and associated service :


<?php 
$apiKey = "";
$ssoToken = "";
$data = file_get_contents("https://api.agendize.com/api/2.0/resellers/accounts?apiKey=$apiKey&token=$ssoToken");
$clients = json_decode($data);

$startDate = date("Y-m-d\T00:00:00P", strtotime('first day of previous month'));
$endDate = date("Y-m-d\T23:59:59P", strtotime('last day of previous month'));

echo "Account\tStart\tEnd\tService\n";
foreach ($clients->items as $client) {
    $data4 = file_get_contents("https://api.agendize.com/api/2.1/scheduling/companies?apiKey=$apiKey&token=" . $client->ssoToken);
    $ct3 = json_decode($data4);
    $companyId = 0;
    if ($ct3 != null) {
        foreach ($ct3->items as $key => $value) {
            $data2 = file_get_contents("https://api.agendize.com/api/2.1/scheduling/companies/$value->id/appointments?startDate=$startDate&endDate=$endDate&apiKey=$apiKey&token=" . $client->ssoToken);
            // Please note that next syncToken's page might be retrieved as well
            $rdvs = json_decode($data2);

            foreach ($rdvs->items as $rdv) {
                echo $client->email . "\t";
                $datetime = explode("T", $rdv->start->dateTime);
                echo $datetime[0] . "\t";
                echo $datetime[1] . "\t";
                echo $rdv->service->name . "\n";
            }
        }
    }
}
?>


Login or Signup to post a comment