Getting error code 200 Invalid api key or secret when trying to create meeting with api

I have created two apps, one is OAuth type and the other is JWT. I am using the following php code to create a meeting.

$zoomData = ‘{
“topic”: “API Test”,
“type”: 2,
“start_time”: “2020-04-09T12:02:00”,
“duration”: “60”,
“timezone”: “Pacific/Auckland”,
“password”: “1234”,
“agenda”: “This is a test meeting”,
“settings”: {
“host_video”: true,
“participant_video”: true,
“audio”: “voip”,
“waiting_room”: true
}
}’;

$clientID=“XXXXXXXXXXXXXXXX”;
$clientSecret=“XXXXXXXXXXXXX”;
$content =“grant_type=client_credentials&client_id=$clientID&client_secret=$clientSecret”;
$token_url=“https://zoom.us/oauth/token”;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $token_url,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $content
));

$token = curl_exec($curl);

$zoomData = json_encode($zoomData);

$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => “https://api.zoom.us/v2/users/MYACCOUNTID/meetings”,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => “”,
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => “POST”,
CURLOPT_POSTFIELDS => $zoomData,
CURLOPT_HTTPHEADER => array(“Content-Type: application/json”, "Authorization: Bearer " . json_decode($token)),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo “cURL Error #:” . $err;
} else {
echo $response;
}

I would much prefer to use the JWT app because it seems simpler but I can’t figure out how to code it because I have found no examples anywhere. We want to be able to automatically create zoom meetings via our Wordpress site when someone orders a product.

Any help would be appreciated. Maybe it is something basic I am missing.

Carl

Hi @fow

At the moment when making API calls via JWT token ( new generated ) is having issues. Check the top header “Developer impacting changes during COVID-19” - JWT Token invalid error ( To fix, deactivate and activate your JWT App )

For WordPress site - You can try using this https://wordpress.org/plugins/video-conferencing-with-zoom-api/

Thanks

1 Like

Hey @fow,

You can also try the PHP sample code / libraries for generating a JWT Token here: https://jwt.io/

Thanks,
Tommy

thank you - looked at the wordpress app and it may be what i have to resort to but i want the flexibility of using my own code and using where needed.

Right now i can’t understand why my oauth app setup works fine on testing https://marketplace.zoom.us/docs/api-reference/zoom-api/meetings/meetingcreate

but will not work from our site - {“code”:200,“message”:“Invalid api key or secret.”} keeps getting returned. Why do i need api key or secret when i have used oauth??? It is not needed on the zoom testing page.

thank you for the link. Still trying to push through and make oauth work as i have successfully used it with wordpress and magento 2. Something is not working with this zoom api though. my code is exactly what the zoom testing page uses… i get success with the test but not on our website.

Do i need to put an api key and secret into the code somewhere?

Gave up using the OAuth generated token and simply used a JWT token generated by the app and pasted that into the code. It now works.
I have been to https://jwt.io/ to look at how to programmatically create a token. Looks complicated.

Is it safe to use the token generated by the app for a long time? i.e. make the expiry date last for 1 year?

Edit (found the answer that this is NOT ok): “Within the App Credentials page of your JWT app, you will see an option to View JWT Token. Here you can quickly generate a temporary token using the current API Key and Secret for the given expiration time. This single temporary token can then be used to test Zoom APIs, but should never be used in production applications.”

Having same issues here with OAuth. Have a feeling given all the recent changes something else backend wise is happening, as code I had failing last week for getting an Access Token is now working today.

1 Like

Hey @fow,

Make sure you are setting the API Key and Secret as the Basic auth header when doing the OAuth flow.

Yes, when using JWT Tokens, it is best to generate the token each time you make a request.

Thanks,
Tommy

1 Like

Hey @StudioBuddy,

Happy to hear it is working now. Let us know if you run into any other issues. :slight_smile:

Thanks,
Tommy

Thank you for the tip @techies23 regarding the Wordpress plugin. I installed it and took a look at his code to see how JWT was implemented. Uses firebase php-jwt. I now have it all working

Final working code is:

<?php

use \Firebase\JWT\JWT;

$key    = XXXXXX;
$secret = XXXXXX;

$token = array(
	"iss" => $key,
	"exp" => time() + 3600 //60 seconds as suggested
);

$jwttoken = JWT::encode( $token, $secret );

$zoomData = array(  "topic" => "TEST Meeting",  "type" => "2",  "start_time" => "2020-04-11T20:00:00",  "duration" => "60",  "timezone" => "Pacific/Auckland",  "password" => "1234",  "settings" => array ("waiting_room" => "true","audio" => "voip"));
$zoomData = json_encode($zoomData);

$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => “https://api.zoom.us/v2/users/EMAIL@EXAMPLE.COM/meetings”,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => “”,
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => “POST”,
CURLOPT_POSTFIELDS => $zoomData,
CURLOPT_HTTPHEADER => array(“Content-Type: application/json”, "Authorization: Bearer " . $jwttoken),
));

$response = curl_exec($curl);
curl_close($curl);

?>

2 Likes

Thanks for sharing your solution with us!