phpjwtzoom-sdkphp-jwt

Pre-scheduling Zoom meeting doesn't create meeting at the time which is supposed? How can I fix it?


The problem is that, Zoom creates meeting but not in the correct time as I am expecting it to be:

I have tried changing timezones in api.php as I have suspected that creates a problem, but seems like it isn't that. Here, I will elaborate how things are connected and place in expected results:

First of all, this is my payment-successful.php page (which is showing up after the payment has been made) and here, I am actually sending the data in form of the array so I can use it later-on inside of api.php:

payment-successful.php:

$newDate = date("Y-m-d", strtotime($apoDate));
$newTime = " " . $apoTime . ":00";



$startTime = date($apoDate . $apoTime);
function password_generate($chars) 
{
  $data = '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcefghijklmnopqrstuvwxyz';
  return substr(str_shuffle($data), 0, $chars);
}

include('config.php');
include('api.php');
$arr['topic']='meinegutebewerbung.de meeting' . password_generate(1);
$arr['start_date']=$startTime;
$arr['duration']=45;
$arr['password']=password_generate(7);
$arr['type']='2';
$result=createMeeting($arr);
if(isset($result->id)){
    echo "Join URL: <a href='".$result->join_url."'>".$result->join_url."</a><br/>";
    echo "Password: ".$result->password."<br/>";
    echo "Start Time: ".$result->start_time."<br/>";
    echo "Duration: ".$result->duration."<br/>";
}else{
    echo '<pre>';
    print_r($result);
}

API call is working (in sense that it actually creates Zoom meeting), the problem is that scheduled meeting is not on the right time and in right date:

When filling out the form user can pick-up the date(from <input type=date>) and select the time from <select> <option>16:00</option> ... </select> (as client wanted for users to be able to pick the time only in the time span of 16:00 (04:00) to 20:00 (08:00);

I get this $apoTime and $apoDate from $_POST['AppointmentDate'] and $_POST['AppointmentTime'].

In this case (for testing purposes) I have selected 12-12-2022 and 16:00 as the selected time and for the output of $result->start_time I am getting: Start Time: 2022-12-13T01:00:00Z ; while obviously I want it to be 2022-12-12T16:00:00Z. Also when I click on the link and launch the meeting and open it inside of the Zoom app it's date is 2022-12-13 and time is 02:00AM

My api.php createMeeting function is is like this:

function createMeeting($data = array())
{
    $post_time = $data['start_date'];
    $start_time = gmdate("Y-m-d\TH:i:s", strtotime($post_time));

    $createMeetingArr = array();
    if (!empty($data['alternative_host_ids']))
    {
        if (count($data['alternative_host_ids']) > 1)
        {
            $alternative_host_ids = implode(",", $data['alternative_host_ids']);
        }
        else
        {
            $alternative_host_ids = $data['alternative_host_ids'][0];
        }
    }

    $createMeetingArr['topic'] = $data['topic'];
    $createMeetingArr['agenda'] = !empty($data['agenda']) ? $data['agenda'] : "";
    $createMeetingArr['type'] = !empty($data['type']) ? $data['type'] : 2; //Scheduled
    $createMeetingArr['start_time'] = $start_time;
    $createMeetingArr['timezone'] = 'Europe/Sarajevo ';
    $createMeetingArr['password'] = !empty($data['password']) ? $data['password'] : "";
    $createMeetingArr['duration'] = !empty($data['duration']) ? $data['duration'] : 60;

    $createMeetingArr['settings'] = array(
        'join_before_host' => !empty($data['join_before_host']) ? true : false,
        'host_video' => !empty($data['option_host_video']) ? true : false,
        'participant_video' => !empty($data['option_participants_video']) ? true : false,
        'mute_upon_entry' => !empty($data['option_mute_participants']) ? true : false,
        'enforce_login' => !empty($data['option_enforce_login']) ? true : false,
        'auto_recording' => !empty($data['option_auto_recording']) ? $data['option_auto_recording'] : "none",
        'alternative_hosts' => isset($alternative_host_ids) ? $alternative_host_ids : ""
    );

    $request_url = "https://api.zoom.us/v2/users/" . EMAIL_ID . "/meetings";
    $token = array(
        "iss" => API_KEY,
        "exp" => time() + 3600 //60 seconds as suggested
        
    );
    $getJWTKey = JWT::encode($token, API_SECRET);
    $headers = array(
        "authorization: Bearer " . $getJWTKey,
        "content-type: application/json",
        "Accept: application/json",
    );

    $fieldsArr = json_encode($createMeetingArr);

    $ch = curl_init();
    curl_setopt_array($ch, array(
        CURLOPT_URL => $request_url,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => "",
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 30,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => "POST",
        CURLOPT_POSTFIELDS => $fieldsArr,
        CURLOPT_HTTPHEADER => $headers,
    ));

    $result = curl_exec($ch);
    $err = curl_error($ch);
    curl_close($ch);
    if (!$result)
    {
        return $err;
    }
    return json_decode($result);
}

I have a feeling that I am doing this wrong in a sense that I am mixing-up timezones and/or the problem is withing my gmdate function, maybe I need to use some other function (I haven't try to change that, as I don't know what else function to try), but I am not 100% sure. Can somebody help me to solve this?

I am also using: https://github.com/firebase/php-jwt


Solution

  • Inside of your payment-successful.php, use following:

    $newDate = date("Y-m-d", strtotime($apoDate));
    $newTime = "T" . $apoTime . ":00";
    $startingTime = $newDate . $newTime;
    

    After it for $arr['start_date']:

    $arr['start_date']=$startingTime;
    

    And inside of your api.php file, instead of using gmdate() function, just use value of 'start_date' as it is:

    $post_time = $data['start_date'];
    

    and down there:

    $createMeetingArr['start_time'] = $post_time;
    

    Also, for this to work I suppose that you haven't updated your Zoom profile, so in order for this to work go onto Zoom My Profile: zoom.us/myprofile

    And set up your time zone to wanted one, second thing is to do is to setup your date format to be in yyyy/mm/dd and Time format to use 24hours format.