Working with Zoom API with PHP

Hello!

I need to Zoom meetings to my website. So I need to generate meeting and links to join it. I have some questions about it. Is it possible to do this on free account? What API i must use? (I prefer users join meeting without login if its possible).

In my development I am tried to make different requests, but I am always getting in response:
“Invalid access token.”

I tried different ways, and with herokuapp.com, i have a lot of progress, but “continue” button not working for me, when I logged in.

I prefer the simplest solution, te create meeting and make join link, please help me with that, maybe some examples on PHP.

herokuapp CODE:
$url = ‘https://xxxxxx.herokuapp.com’;
$data = array(‘meetingNumber’ => ‘’, ‘role’ => ‘0’);

// use key 'http' even if you send the request to https://...
$options = array(
    'http' => array(
        'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
        'method'  => 'POST',
        'content' => http_build_query($data)
    )
);
$context  = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) { /* Handle error */ }

//var_dump($result);
$resAr = json_decode($result, true);
$signature = $resAr['signature'];
echo '
<div class="iframe-container" style="overflow: hidden; padding-top: 56.25%; position: relative;">
	<iframe allow="microphone; camera" style="border: 0; height: 100%; left: 0; position: absolute; top: 0; width: 100%;" src="https://success.zoom.us/wc/join/7945472637" frameborder="0"></iframe>
</div>
';

Or I try to make simple post request and I am getting wrong auth token:
$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.zoom.us/v2/users//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 => "{\"topic\":\"string\",\"type\":\"integer\",\"start_time\":\"string [date-time]\",\"duration\":\"integer\",\"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\"}}",
  CURLOPT_HTTPHEADER => array(
    "authorization: Bearer g9o8vEE4wX_AoePQ40lQ5aEkQU-L4BB6A",
    "content-type: application/json"
  ),
));

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

curl_close($curl);

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

Hey @maksim,

Looks like you are just passing in your JWT API Key and not your JWT Token.

"authorization: Bearer {JWT TOKEN HERE}"

Follow the guides here to embed the created meeting into your site:

Thanks,
Tommy

You can create Zoom Meeting Using JWT API using the Following Php Code

    <?php

require_once 'config.php';


class Zoom_Api
{


    protected function sendRequest($data)
    {
        $request_url = "https://api.zoom.us/v2/users//meetings";




        $postFields =  '{
        "topic": "New Meeting",
        "type": 2,
        "start_time": "2020-08-09T12:00:00Z",
        "duration": 45,
        "timezone": "America/Anchorage",
        "password": "1234",
        "agenda": "Zoom WordPress",
        "tracking_fields": [
          {
            "field": "string",
            "value": "string"
          }
        ],
        "settings": {
          "host_video": true,
          "participant_video": true,
          "cn_meeting": false,
          "in_meeting": false,
          "join_before_host": false,
          "mute_upon_entry": true,
          "watermark": false,
          "use_pmi": false,
          "approval_type": 0,
          "registration_type": 1,
          "audio":"voip", 
          "enforce_login": false,
          "enforce_login_domains": "",
          "alternative_hosts": "",
          "registrants_email_notification": false
        }
      }';



        $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 => $postFields,
            CURLOPT_HTTPHEADER => array(
                "authorization: Bearer",
                "content-type: application/json",
                "Accept: application/json",
            ),
        ));


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

    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']   = 'PST';
        $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 json_encode($z);
} catch (Exception $ex) {
    echo $ex;
}
1 Like

Hey @nawoapp1,

Thanks for contributing to the Zoom Developer Community! :slight_smile:

Thanks,
Tommy

Hi there. Where can one get a clear, simple example of joining Zoom meeting from a PHP app.

We have users in our database already. We want them to click one link and join a meeting. This should work for web and mobile so I doubt web sdk would the best fit.

We have setup outh0 but there is no clear guide that shows the custom app - auth0 - Zoom flow.

Most guides assume the developer should know certain concepts already.

Kindly assist

Hey @webrave,

Users simply have to click on the join_url to join the meeting. What specifically are you needing help with?

Thanks,
Tommy

Hi Tommy. I finally figured that out thanks. Nonetheless I would still like to get a guide on implementing the SSO. The Outh0-Zoom flow seems straight forward. I struggle with the app side of things. Basically developing from PHP.

1 Like

Happy to hear you figured it out! :slight_smile:

Thanks for your feedback!

-Tommy

Having Problem when using same API with php CURL
but it works with post man
http://api.zoom.us/v2/users?page_size=300&status=active
User-Agent: Zoom-Jwt-Request
Authorization:Bearer [Redacted]
Content-Type:application/json

Hi, @pratham,

Welcome to the Developer Forum – happy to help. Can you share more details about the behavior you are seeing with the PHP CURL API request? If possible, please share a screenshot or video (with your personal identifiable information omitted) of the behavior you are seeing. This information will help diagnose what may be happening.

I’d also suggested searching for the forum for Curl PHP solutions, as the answer you may be available already. For reference, here is a developer forum you may find helpful :

Thanks,
Donte