# Invalid access token while Creating meeting JWT

**URL:** <https://devforum.zoom.us/t/invalid-access-token-while-creating-meeting-jwt/27310>\
**Category:** Web\
**Created:** [August 16, 2020, 6:13pm UTC](https://devforum.zoom.us/t/invalid-access-token-while-creating-meeting-jwt/27310 "2020-08-16T18:13:19Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![m.elsisi](https://avatars.discourse-cdn.com/v4/letter/m/c37758/32.png) [@m.elsisi](https://devforum.zoom.us/u/m.elsisi)\
**Post date:** [August 16, 2020, 6:13pm UTC](https://devforum.zoom.us/t/invalid-access-token-while-creating-meeting-jwt/27310/1 "2020-08-16T18:13:19Z")

</div>

Hi  
i am trying to crate a meeting but it gives me invalid access token , Here is my code

```
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: {$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;
}

```

Any help ???

---

<div class="post-metadata">

**Author:** ![tommy](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/tommy/32/72769_2.png) [@tommy](https://devforum.zoom.us/u/tommy)\
**Post date:** [August 18, 2020, 8:39pm UTC](https://devforum.zoom.us/t/invalid-access-token-while-creating-meeting-jwt/27310/2 "2020-08-18T20:39:38Z")

</div>

Hey @m.elsisi,

Have you tried using the JWT Token generated for you in the marketplace to see if that works?

> **[JSON Web Tokens (JWT) - Authorization - Documentation](https://marketplace.zoom.us/docs/guides/auth/jwt#testing)**
>
> JWT With Zoom
> 
> The Zoom API uses JSON Web Tokens (JWT) to authenticate account-level access. These tokens offer a method to establish secure server-to-s...

Thanks,  
Tommy

---

<div class="post-metadata">

**Author:** ![m.elsisi](https://avatars.discourse-cdn.com/v4/letter/m/c37758/32.png) [@m.elsisi](https://devforum.zoom.us/u/m.elsisi)\
**Post date:** [August 19, 2020, 11:11am UTC](https://devforum.zoom.us/t/invalid-access-token-while-creating-meeting-jwt/27310/3 "2020-08-19T11:11:21Z")

</div>

the JWT generated token in marketplace works fine it gives me this:

> {“page\_count”:1,“page\_number”:1,“page\_size”:30,“total\_records”:1,“users”:[{“[id":“CnbSZ6UvTaCH1qXyo7tk3w”,“first\_name”:“Mohamed”,“last\_name”:“Elsisi”,“email”:"m.elsisi@focuspublish.com](mailto:id%22:%22CnbSZ6UvTaCH1qXyo7tk3w%22,%22first_name%22:%22Mohamed%22,%22last_name%22:%22Elsisi%22,%22email%22:%22m.elsisi@focuspublish.com)”,“type”:1,“pmi”:4235506987,“timezone”:“Africa/Cairo”,“verified”:1,“created\_at”:“2020-06-10T18:17:53Z”,“last\_login\_time”:“2020-08-14T13:15:54Z”,“last\_client\_version”:“5.1.28652.0706(android)”,“language”:“en-US”,“phone\_number”:“”,“status”:“active”}]}

Now what is wrong in my code also how can i get the meeting id and password from the reply ?

---

<div class="post-metadata">

**Author:** ![tommy](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/tommy/32/72769_2.png) [@tommy](https://devforum.zoom.us/u/tommy)\
**Post date:** [August 19, 2020, 10:10pm UTC](https://devforum.zoom.us/t/invalid-access-token-while-creating-meeting-jwt/27310/4 "2020-08-19T22:10:17Z")

</div>

Hey @m.elsisi,

I am not sure what is wrong with your code. You can see libraries here: [jwt.io](http://jwt.io) to help you [generate your JWT Token properly](https://marketplace.zoom.us/docs/guides/auth/jwt).

As for getting the meetingID and passcode, you can use the [Get Meeting API.](https://marketplace.zoom.us/docs/api-reference/zoom-api/meetings/meeting)

Thanks,  
Tommy

---

<div class="post-metadata">

**Author:** ![m.elsisi](https://avatars.discourse-cdn.com/v4/letter/m/c37758/32.png) [@m.elsisi](https://devforum.zoom.us/u/m.elsisi)\
**Post date:** [August 23, 2020, 7:36pm UTC](https://devforum.zoom.us/t/invalid-access-token-while-creating-meeting-jwt/27310/5 "2020-08-23T19:36:14Z")

</div>

hi @tommy  
The link you send is to get meeting id and password for OATH type not JWT type ,  
I want to get the meeting id and password from this token response

> {“page\_count”:1,“page\_number”:1,“page\_size”:30,“total\_records”:1,“users”:[{“id”:“CnbSZ6UvTaCH1qXyo7tk3w”,“first\_name”:“Mohamed”,“last\_name”:“Elsisi”,“email”:“\*\*\*\*\*”,“type”:1,“pmi”:4235506987,“timezone”:“Africa/Cairo”,“verified”:1,“created\_at”:“2020-06-10T18:17:53Z”,“last\_login\_time”:“2020-08-14T13:15:54Z”,“last\_client\_version”:“5.1.28652.0706(android)”,“language”:“en-US”,“phone\_number”:“”,“status”:“active”}]}

---

<div class="post-metadata">

**Author:** ![tommy](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/tommy/32/72769_2.png) [@tommy](https://devforum.zoom.us/u/tommy)\
**Post date:** [August 24, 2020, 10:09pm UTC](https://devforum.zoom.us/t/invalid-access-token-while-creating-meeting-jwt/27310/6 "2020-08-24T22:09:33Z")

</div>

Hey @m.elsisi,

You can still use a JWT App to call the [Get Meeting API](https://marketplace.zoom.us/docs/api-reference/zoom-api/meetings/meeting).

Just pass in the authorization token as the auth header.

`"Authorization": "Bearer JWT_TOKEN_HERE"`

Thanks,  
Tommy

---

<div class="post-metadata">

**Author:** ![m.elsisi](https://avatars.discourse-cdn.com/v4/letter/m/c37758/32.png) [@m.elsisi](https://devforum.zoom.us/u/m.elsisi)\
**Post date:** [August 27, 2020, 6:03pm UTC](https://devforum.zoom.us/t/invalid-access-token-while-creating-meeting-jwt/27310/7 "2020-08-27T18:03:38Z")

</div>

HI @tommy  
The Get Meeting API needs a meeting id to retrieve its info , but as you see the response i get doesn’t contain a meeting id , it has only id ( i don’t know id refers to what )  
and i am passing the Authorization token to auth header  
here is my code :

```
> <?php
> require_once 'vendor/firebase/phpjwt/src/BeforeValidException.php';
> require_once 'vendor/firebase/phpjwt/src/ExpiredException.php';
> require_once 'vendor/firebase/phpjwt/src/SignatureInvalidException.php';
> require_once 'vendor/firebase/phpjwt/src/JWT.php';
> 
> 
> use \Firebase\JWT\JWT;
> $zoom_api_key = ' ******';
> $zoom_api_secret = ' *****';
> 		
> $curl = curl_init();
> 
> curl_setopt_array($curl, array(
> CURLOPT_URL => "https://api.zoom.us/v2/users?status=active&page_size=30&page_number=1",
> CURLOPT_RETURNTRANSFER => true,
> CURLOPT_ENCODING => "",
> CURLOPT_MAXREDIRS => 10,
> CURLOPT_TIMEOUT => 30,
> CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
> CURLOPT_CUSTOMREQUEST => "GET",
> CURLOPT_HTTPHEADER => array(
> "authorization:Bearer My token",
> "content-type: application/json"
> ),
> ));
> 
> $response = curl_exec($curl);
> $err = curl_error($curl);
> 
> curl_close($curl);
> 
> if ($err) {
> echo "cURL Error #:" . $err;
> } else {
> echo $response;
> }
> ?>
```

---

<div class="post-metadata">

**Author:** ![tommy](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/tommy/32/72769_2.png) [@tommy](https://devforum.zoom.us/u/tommy)\
**Post date:** [August 28, 2020, 7:18pm UTC](https://devforum.zoom.us/t/invalid-access-token-while-creating-meeting-jwt/27310/8 "2020-08-28T19:18:26Z")

</div>

Hey @m.elsisi,

You can get a meeting ID from the [Meeting webhooks](https://marketplace.zoom.us/docs/api-reference/webhook-reference/meeting-events/meeting-created), or the [List Meetings endpoint](https://marketplace.zoom.us/docs/api-reference/zoom-api/meetings/meetings).

Thanks,  
Tommy

---

<div class="post-metadata">

**Author:** ![m.elsisi](https://avatars.discourse-cdn.com/v4/letter/m/c37758/32.png) [@m.elsisi](https://devforum.zoom.us/u/m.elsisi)\
**Post date:** [September 12, 2020, 3:55pm UTC](https://devforum.zoom.us/t/invalid-access-token-while-creating-meeting-jwt/27310/9 "2020-09-12T15:55:26Z")

</div>

Hi @tommy  
Sorry for the late reply  
The meeting webhooks and list meeting endpoints are for Oath type ( they ask for Client ID and Client Secret ) i am using JWT , so how can i retrieve the meeting ID and Password , I would appreciate if there is a PHP example i can follow

---

<div class="post-metadata">

**Author:** ![tommy](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/tommy/32/72769_2.png) [@tommy](https://devforum.zoom.us/u/tommy)\
**Post date:** [September 15, 2020, 5:44pm UTC](https://devforum.zoom.us/t/invalid-access-token-while-creating-meeting-jwt/27310/10 "2020-09-15T17:44:28Z")

</div>

Hey @m.elsisi,

You can use a JWT App to call the API and enable Webhooks. 🙂

Just [generate a JWT Token to make API requests](https://marketplace.zoom.us/docs/guides/auth/jwt#testing).

And here is how to [enable webhooks in a JWT App](https://marketplace.zoom.us/docs/guides/build/jwt-app#features).

Thanks,  
Tommy

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/zoomdeveloper/original/3X/6/1/614bdd549b610bbaa46ff934617683a02bdaa03c.png) [@system](https://devforum.zoom.us/u/system)\
**Post date:** [October 16, 2020, 3:44am UTC](https://devforum.zoom.us/t/invalid-access-token-while-creating-meeting-jwt/27310/11 "2020-10-16T03:44:31Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
