Help with api create meeting with php

Hi All,

I am having issues getting the create meeting to work with PHP using JWT. I have validated that my Bearer token is valid using jwt.io but anytime I make a call to create the meeting I get “invalid access token” Can someone take a look at my code below and let me know/point me in the right direction to get his working correctly? Thanks in advance!

use \Firebase\JWT\JWT;
class Zoom_Api {
		private $zoom_api_key = '###';
		private $zoom_api_secret = '#####';
		
		protected function sendRequest($data) {
            $request_url = 'https://api.zoom.us/v2/users/me/meetings';
            $headers = array(
				'authorization' => 'Bearer ' . $this->generateJWTKey(),
				'content-type'  => 'application/json'
            );
           $postFields = json_encode($data);
		   $ch = curl_init();
			curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
			curl_setopt($ch, CURLOPT_URL, $request_url);
			curl_setopt($ch, CURLOPT_POST, 1);
			curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
			$response = curl_exec($ch);
			$err = curl_error($ch);
			curl_close($ch);
			if(!$response){
				return $err;
			}
			return json_decode($response);
		}

		//function to generate JWT
        private function generateJWTKey() {
            $key = $this->zoom_api_key;
            $secret = $this->zoom_api_secret;
            $token = array(
                "iss" => $key,
                "exp" => time() + 3600 //60 seconds as suggested
            );
            return JWT::encode( $token, $secret );
        }
		
		public function createAMeeting( $data = array() ) {
            $post_time  = $data['start_date'];
			$start_time = gmdate( "Y-m-d\TH:i:s", strtotime( $post_time ) );
            $createAMeetingArray = 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];
                }
            }
            $createAMeetingArray['topic']      = $data['meetingTopic'];
            $createAMeetingArray['agenda']     = ! empty( $data['agenda'] ) ? $data['agenda'] : "";
            $createAMeetingArray['type']       = ! empty( $data['type'] ) ? $data['type'] : 2; //Scheduled
            $createAMeetingArray['start_time'] = $start_time;
            $createAMeetingArray['timezone']   = $data['timezone'];
            $createAMeetingArray['password']   = ! empty( $data['password'] ) ? $data['password'] : "";
            $createAMeetingArray['duration']   = ! empty( $data['duration'] ) ? $data['duration'] : 60;
            $createAMeetingArray['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 : ""
            );
            return $this->sendRequest($createAMeetingArray);
        }

	}
}

$zoom_meeting = new Zoom_Api();
try{
$z = $zoom_meeting->createAMeeting(
	array(
		'start_date'=>date("Y-m-d h:i:s", strtotime('tomorrow')),
		'topic'=>'Example Test Meeting'
	)
);
echo $z->message;
} catch (Exception $ex) {
echo $ex;
}

Try with this:

$headers = array(
“authorization: {$this->generateJWTKey()}”,
‘content-type: application/json’
);

The problem is that you’re using ‘=>’ in the definition of your $headers array.

2 Likes

Thanks Ruben!

@mike1 let us know if this works for you!

It’s working for me!

Great! Thanks for your help Ruben!

Yep its working. Thanks Ruben!

Funny how you miss something little when you have been starring at a code screen all day :slight_smile:

1 Like

One note though I had to keep the Bearer text like so
$headers = array(
‘authorization: Bearer ‘.$this->generateJWTKey().’’,
‘content-type:application/json’
);

2 Likes

Haha happens to everyone! Glad it’s working now!

I Cant Run The Code Plz Help Me

<?php use \Firebase\JWT\JWT; class Zoom_Api { private $zoom_api_key = 'V0vJUrlBS---HWT7jX2GXQ'; private $zoom_api_secret = 'Gm4o0mVsXk5qdlo71hFfJucqc2V1UeBhQqAa'; protected function sendRequest($data) { $request_url = 'https://api.zoom.us/v2/users/me/meetings'; $headers = array( “authorization: {$this->generateJWTKey()}”, ‘content-type: application/json’ ); $postFields = json_encode($data); $ch = curl_init(); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_URL, $request_url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($ch); $err = curl_error($ch); curl_close($ch); if(!$response){ return $err; } return json_decode($response); } //function to generate JWT private function generateJWTKey() { $key = $this->zoom_api_key; $secret = $this->zoom_api_secret; $token = array( "iss" => $key, "exp" => time() + 3600 //60 seconds as suggested ); return JWT::encode( $token, $secret ); } public function createAMeeting( $data = array() ) { $post_time = $data['start_date']; $start_time = gmdate( "Y-m-d\TH:i:s", strtotime( $post_time ) ); $createAMeetingArray = 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]; } } $createAMeetingArray['topic'] = $data['meetingTopic']; $createAMeetingArray['agenda'] = ! empty( $data['agenda'] ) ? $data['agenda'] : ""; $createAMeetingArray['type'] = ! empty( $data['type'] ) ? $data['type'] : 2; //Scheduled $createAMeetingArray['start_time'] = $start_time; $createAMeetingArray['timezone'] = $data['timezone']; $createAMeetingArray['password'] = ! empty( $data['password'] ) ? $data['password'] : ""; $createAMeetingArray['duration'] = ! empty( $data['duration'] ) ? $data['duration'] : 60; $createAMeetingArray['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 : "" ); return $this->sendRequest($createAMeetingArray); } } } $zoom_meeting = new Zoom_Api(); try{ $z = $zoom_meeting->createAMeeting( array( 'start_date'=>date("Y-m-d h:i:s", strtotime('tomorrow')), 'topic'=>'Example Test Meeting' ) ); echo $z->message; } catch (Exception $ex) { echo $ex; } ?>

Hey @shady.work.it,

Please provide a description of what you are trying to do. Your post is very unreadable.

Thanks,
Tommy

Help Invalid access token.

class ZoomController
{

private $zoom_api_key = 'key';

private $zoom_api_secret = 'secret';

public function zoom()
{

    #$zoom_meeting = new ZoomController();

    try{

    $z = $this->createAMeeting(

        array(

            'start_date'=>date("Y-m-d h:i:s", strtotime('tomorrow')),

            'topic'=>'Example Test Meeting'

        )

    );

    echo $z->message;

    } catch (Exception $ex) {

    echo $ex;

    }

}



protected function sendRequest($data)
{

    $request_url = 'https://api.zoom.us/v2/users/12345678901/meetings';

    $headers = array ("authorization: {$this->generateJWTKey()}", "content-type:application/json");

    
   $postFields = json_encode($data);

   $ch = curl_init();

    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);

    curl_setopt($ch, CURLOPT_URL, $request_url);

    curl_setopt($ch, CURLOPT_POST, 1);

    curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 

    $response = curl_exec($ch);

    $err = curl_error($ch);

    curl_close($ch);

    if(!$response){

        return $err;

    }

    return json_decode($response);

}

//function to generate JWT

private function generateJWTKey() 

{

    $key = $this->zoom_api_key;

    $secret = $this->zoom_api_secret;

    $token = array(

        "iss" => $key,

        "exp" => time() + 3600 //60 seconds as suggested

    );

    

    return JWT::encode( $token, $secret );

}



public function createAMeeting( $data = array() ) 

{

    $post_time  = $data['start_date'];

    $start_time = gmdate( "Y-m-d\TH:i:s", strtotime( $post_time ) );

    $createAMeetingArray = 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];

        }

    }

    $createAMeetingArray['topic']      = $data['topic'];

    $createAMeetingArray['agenda']     = ! empty( $data['agenda'] ) ? $data['agenda'] : "";

    $createAMeetingArray['type']       = ! empty( $data['type'] ) ? $data['type'] : 2; //Scheduled

    $createAMeetingArray['start_time'] = $start_time;

    $createAMeetingArray['timezone']   = $start_time;

    $createAMeetingArray['password']   = ! empty( $data['password'] ) ? $data['password'] : "";

    $createAMeetingArray['duration']   = ! empty( $data['duration'] ) ? $data['duration'] : 60;

    $createAMeetingArray['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 : ""

    );

    return $this->sendRequest($createAMeetingArray);

}

}

[settings] => stdClass Object ( [host_video] => 1 [participant_video] => [cn_meeting] => [in_meeting] => [join_before_host] => 1 [mute_upon_entry] => 1 [watermark] => [use_pmi] => [approval_type] => 2 [audio] => voip [auto_recording] => local [enforce_login] => [enforce_login_domains] => [alternative_hosts] => [close_registration] => [registrants_confirmation_email] => 1 [waiting_room] => 1 [registrants_email_notification] => 1 [meeting_authentication] => )

i dont want this i just only need this
stdClass Object ( [uuid] => yVVnTofJSn+qG4B0DWMUZw== [id] => *********** [host_id] => NOGCFsCyRwe_cvyntO6s7g [topic] => යාපා බණ්ඩාර Sir Class [type] => 2 [status] => waiting [start_time] => 2020-05-30T04:30:00Z [duration] => 60 [timezone] => Asia/Kolkata [created_at] => 2020-05-29T00:02:29Z [start_url] => https://us04web.zoom.us/s/77386204622?zak=eyJ6bV9za20iOiJ6bV9vMm0iLCJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJjbGllbnQiLCJ1aWQiOiJOT0dDRnNDeVJ3ZV9jdnludE82czdnIiwiaXNzIjoid2ViIiwic3R5IjoxLCJ3Y2QiOiJ1czA0IiwiY2x0IjowLCJzdGsiOiJWbGpfZ2ZJSkVOVWYwdmJGX1hlcGhWQzVpV21tcHEzTmVsY1YtdnZrLTVZLkVnSUFBQUZ5WGJ5Nnd3QUFIQ0FnZGpoNVJpdDRkVFpWWTNremFFODRMMHhKUVVoUGQzRkRaVE5XVUVsSGQzZ0FERE5EUWtGMWIybFpVek56UFFSMWN6QTAiLCJleHAiOjE1OTA3MTc3NDksImlhdCI6MTU5MDcxMDU0OSwiYWlkIjoiX28wVW1oVjlTN3l3bmZ0Rm52bEZEdyIsImNpZCI6IiJ9.V55D97nzAMnad7MH1gtjgZGuOu4_mI75iA9w8OnNekc [join_url] => https://us04web.zoom.us/j/77386204622?pwd=YW50VFlSVWpYNllybFJxK3hNa3pMZz09 [password] => 1tHNZ2 [h323_password] => 465928 [pstn_password] => 465928 [encrypted_password] => YW50VFlSVWpYNllybFJxK3hNa3pMZz09

how can i do that

*This post has been edited to remove any meeting / webinar IDs

This worked for me
$headers = array( “authorization: Bearer {$this-> generateJWTKey()}”,
“content-type: application/json” );

Hey Mike!!
Can you help about api create meeting. I’m new to zoom and i want to create meeting using php and jwt can you provide me your sample app with php code.
thanks regards

Hi @junaidali9559 from our Create a Meeting API docs:

This uses the pecl/http2 library:

<?php

$client = new http\Client;
$request = new http\Client\Request;

$body = new http\Message\Body;
$body->append('{"topic":"string","type":"integer","start_time":"string [date-time]","duration":"integer","schedule_for":"string","timezone":"string","password":"string","agenda":"string","recurrence":{"type":"integer","repeat_interval":"integer","weekly_days":"string","monthly_day":"integer","monthly_week":"integer","monthly_week_day":"integer","end_times":"integer","end_date_time":"string [date-time]"},"settings":{"host_video":"boolean","participant_video":"boolean","cn_meeting":"boolean","in_meeting":"boolean","join_before_host":"boolean","mute_upon_entry":"boolean","watermark":"boolean","use_pmi":"boolean","approval_type":"integer","registration_type":"integer","audio":"string","auto_recording":"string","enforce_login":"boolean","enforce_login_domains":"string","alternative_hosts":"string","global_dial_in_countries":["string"],"registrants_email_notification":"boolean"}}');

$request->setRequestUrl('https://api.zoom.us/v2/users/xxxxxxxxxxxx/meetings');
$request->setRequestMethod('POST');
$request->setBody($body);

$request->setHeaders(array(
  'content-type' => 'application/json',
  'authorization' => 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOm51bGwsImlzcyI6InZlVmFjM1pUUV8tT3JTR1hRaDNvUEEiLCJleHAiOjE1ODczNDU4NTUsImlhdCI6MTU4NzM0MDQ1NX0.UP9SEMsrh10zBfwrIyAeo-pMyOlRYVqXMhW4TGZemM0'
));

$client->enqueue($request)->send();
$response = $client->getResponse();

echo $response->getBody();

Hi all,
I am having issues getting the create meeting to work with PHP using JWT. i am getting blank page please help me to solve my issue.Thanks in advance.

<?php require_once 'jwt/BeforeValidException.php';
require_once 'jwt/ExpiredException.php';
require_once 'jwt/SignatureInvalidException.php';
require_once 'jwt/JWT.php';
use \Firebase\JWT\JWT;
class Zoom_Api {
private $zoom_api_key = 'xxxxx';
private $zoom_api_secret = 'xxxxxx';
protected function sendRequest($data) {
$request_url = 'https://api.zoom.us/v2/users/me/meetings';
$headers = array(
"authorization: {$this->generateJWTKey()}",
'content-type: application/json'
);
$postFields = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_URL, $request_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
$err = curl_error($ch);
curl_close($ch);
if(!$response){
return $err;
}
return json_decode($response);
}
//function to generate JWT
private function generateJWTKey() {
$key = $this->zoom_api_key;
$secret = $this->zoom_api_secret;
$token = array(
"iss" => $key,
"exp" => time() + 3600 //60 seconds as suggested
);
// $token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOm51bGwsImlzcyI6Ik5EdlI3TnN2U1ZLM2FqNEdGOWpKY1EiLCJleHAiOjE1OTI1NzA1OTksImlhdCI6MTU5MjU2NTIwMH0.P_WVeUtIOuaHp9MslWWPhyfoDelSSceARVxHucYT-yM"; return JWT::encode( $token, $secret ); }
public function createAMeeting( $data = array() ) {
$post_time = $data['start_date'];
$start_time = gmdate( "Y-m-d\TH:i:s", strtotime( $post_time ) );
$createAMeetingArray = 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];
}
}
$createAMeetingArray['topic'] = $data['meetingTopic'];
$createAMeetingArray['agenda'] = ! empty( $data['agenda'] ) ? $data['agenda'] : "";
$createAMeetingArray['type'] = ! empty( $data['type'] ) ? $data['type'] : 2; //Scheduled
$createAMeetingArray['start_time'] = $start_time;
$createAMeetingArray['timezone'] = $data['timezone'];
$createAMeetingArray['password'] = ! empty( $data['password'] ) ? $data['password'] : "";
$createAMeetingArray['duration'] = ! empty( $data['duration'] ) ? $data['duration'] : 60;
$createAMeetingArray['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 : ""
);
return $this->sendRequest($createAMeetingArray);
}
}
$zoom_meeting = new Zoom_Api();
try{
$z = $zoom_meeting->createAMeeting(
array(
'start_date'=>date("Y-m-d h:i:s", strtotime('tomorrow')),
'meetingTopic'=>'Example Test Meeting',
'timezone'=>'Asia/Tashkent'
)
);
print_r($z);
} catch (Exception $ex) {
echo $ex;
}
?>

Hey @yash.sakali,

Please share a screenshot of the blank page issue. Also make sure you are making a POST request to create the meeting.

Thanks,
Tommy

Thank you for your valuable response.its working now…if any issue I will mail you…

1 Like

Happy to hear you got it working!

Thanks,
Tommy