Found a solution on my previous problem/confusion: for others who also having same question kindly see solutions bellow:
Installed JWT Library (for this example I tried using php-jwt from Firebase: you can also check other library from: https://jwt.io/)
Install the library:
composer require firebase/php-jwt
Build a JWT App:
-
-
-
- Fill-up all the field needed
- Use the Credential to the API Integration that is shown bellow
Create your file to Integrate to the API calls:
<?php
require_once 'vendor/firebase/php-jwt/src/BeforeValidException.php';
require_once 'vendor/firebase/php-jwt/src/ExpiredException.php';
require_once 'vendor/firebase/php-jwt/src/SignatureInvalidException.php';
require_once 'vendor/firebase/php-jwt/src/JWT.php';
use \Firebase\JWT\JWT;
class Zoom_Api {
private $zoom_api_key = 'YOUR_ZOOM_API_APP_KEY';
private $zoom_api_secret = 'YOUR_ZOOM_API_APP_SECRETE';
protected function sendRequest($data) {
$request_url = 'https://api.zoom.us/v2/webinars/{webinarId}/registrants';
$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
);
// $token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOm51bGwsImlzcyI6IlI1OWZNMEViUXFPcWNrU0c4dzR2MmciLCJleHAiOjE1OTA1MTM4NDUsImlhdCI6MTU5MDUwODQ0N30.4ch2OZoFM_vZFdqhoMzJX8r8GPYjKlOkV_vUa7LprFc";
return JWT::encode( $token, $secret );
}
public function registerWebinar( $data = array() ) {
$registerToWebinarArray = array();
$registerToWebinarArray['email'] = $data['email'];
$registerToWebinarArray['first_name'] = $data['first_name'] ;
$registerToWebinarArray['last_name'] = $data['last_name'] ;
$registerToWebinarArray['address'] = $data['address'];
$registerToWebinarArray['city'] = $data['city'];
return $this->sendRequest($registerToWebinarArray);
}
}
$zoom_meeting = new Zoom_Api();
$emailRegistrant = $_POST['email'];
$firstNameRegistrant = $_POST['first_name'];
$lastNameRegistrant = $_POST['last_name'];
try{
$z = $zoom_meeting->registerWebinar(
array(
"email" => $emailRegistrant,
"first_name" => $firstNameRegistrant,
"last_name" => $lastNameRegistrant,
"address" => "",
"city" => "",
"country" => "",
"zip" => "",
"state" => "",
"phone" => "",
"industry" => "",
"org" => "",
"job_title" => "",
"purchasing_time_frame" => "",
"role_in_purchase_process" => "",
"no_of_employees" => "",
"comments" => ""
)
);
print_r($z);
} catch (Exception $ex) {
echo $ex;
}
?>
Note: change the {webinarId} to your own Webinar ID.
I hope this helps to those who are looking for this documentation! Thanks!