# Jwt token is not working, giving error "Invalid token"

**URL:** <https://devforum.zoom.us/t/jwt-token-is-not-working-giving-error-invalid-token/22645>\
**Category:** API and Webhooks\
**Created:** [June 29, 2020, 11:18am UTC](https://devforum.zoom.us/t/jwt-token-is-not-working-giving-error-invalid-token/22645 "2020-06-29T11:18:27Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![tiwari.jyoti.05](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/tiwari.jyoti.05/32/11152_2.png) [@tiwari.jyoti.05](https://devforum.zoom.us/u/tiwari.jyoti.05)\
**Post date:** [June 29, 2020, 11:18am UTC](https://devforum.zoom.us/t/jwt-token-is-not-working-giving-error-invalid-token/22645/1 "2020-06-29T11:18:27Z")

</div>

Hi,

I am trying to integrate Zoom meetings with my php application, for integration using Zoom API. when I am sending a request to Zoom server to create a meeting getting {“code”:124,“message”:“Invalid access token.”} error. I have also verified token in “[https://jwt.io](https://jwt.io)”. but not working in my application.  
I am able to successfully create a meeting with same API key and API Secret in my another wordpress application but not working in my custom application.

I am using free basic trial account in zoom.

Please help me.

Thanks.

---

<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:** [June 30, 2020, 9:21pm UTC](https://devforum.zoom.us/t/jwt-token-is-not-working-giving-error-invalid-token/22645/2 "2020-06-30T21:21:24Z")

</div>

Hey @tiwari.jyoti.05,

How are you setting the authorization header? If it is working on another application, but not on yours, there must be something off with how you are sending the request or generating the JWT Token.

Thanks,  
Tommy

---

<div class="post-metadata">

**Author:** ![tiwari.jyoti.05](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/tiwari.jyoti.05/32/11152_2.png) [@tiwari.jyoti.05](https://devforum.zoom.us/u/tiwari.jyoti.05)\
**Post date:** [July 2, 2020, 9:51am UTC](https://devforum.zoom.us/t/jwt-token-is-not-working-giving-error-invalid-token/22645/5 "2020-07-02T09:51:27Z")

</div>

```
Hi Tommy,

Thanks for reply, below is php code of integration, please review this code and let me know where I am doing wrong

<?php

namespace Drupal\ridishu_zoom_meeting\Controller;

require_once 'G:\php\xampp\htdocs\drupal-8.8.5\drupal-8.8.5\vendor\firebase\php-jwt\src\BeforeValidException.php';
require_once 'G:\php\xampp\htdocs\drupal-8.8.5\drupal-8.8.5\vendor\firebase\php-jwt\src\ExpiredException.php';
require_once 'G:\php\xampp\htdocs\drupal-8.8.5\drupal-8.8.5\vendor\firebase\php-jwt\src\SignatureInvalidException.php';
require_once 'G:\php\xampp\htdocs\drupal-8.8.5\drupal-8.8.5\vendor\firebase\php-jwt\src\JWT.php';

use \Firebase\JWT\JWT;
use Drupal\zoomapi;
use Drupal\Core\Controller\ControllerBase;

/**
 * Defines Zoom_meeting_controller class.
 */
class Zoom_meeting_controller extends ControllerBase {

  /**
   * Display the markup.
   *
   * @return array
   * Return markup array.
   */

private $zoom_api_key = 'key';
private $zoom_api_secret = 'key';

  public function start_meeting() {
    $zoom_meeting = new Zoom_meeting_controller();
try{
    $z = $zoom_meeting->createAMeeting(array(
'start_date'=>date("Y-m-d h:i:s", strtotime('tomorrow')),
'meetingTopic'=>'Example Test Meeting',
'timezone'=>'Asia/Tashkent',
'alternative_host_ids'=>'ab@gmail.com'
));
print_r($z);
return $z;

} catch (Exception $ex) {
  echo "error in main method............";
//echo $ex;
}

  }

public function createAMeeting( $data = array() ) {
  $post_time = $data['start_date'];
  $start_time = gmdate( "Y-m-d\TH:i:s", strtotime( $post_time ) );
  $createAMeetingArray = array();

  $alternative_host_ids='';

  $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'] : "";
  //echo "1..................";
  $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' => $alternative_host_ids
  );
  return $this->sendRequest($createAMeetingArray);
}

protected function sendRequest($data) {
$email="";
$request_url="https://api.zoom.us/v2/users/".$email."/meetings";
$jwt_token=$this->generateJWTKey();
//$jwt_token="token";
$headers = array(
"Authorization: Bearer ".$jwt_token,
"content-type: application/json"
);

$postFields = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_URL, $request_url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
$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 = "";
$secret = "";
$token = array(
"iss" => $key,
"exp" => time() + 3600 //60 seconds as suggested
);
echo "<br>";
return JWT::encode( $token, $secret );
}

}
?>

Thank,
Jyoti
```

---

<div class="post-metadata">

**Author:** ![tiwari.jyoti.05](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/tiwari.jyoti.05/32/11152_2.png) [@tiwari.jyoti.05](https://devforum.zoom.us/u/tiwari.jyoti.05)\
**Post date:** [July 2, 2020, 9:55am UTC](https://devforum.zoom.us/t/jwt-token-is-not-working-giving-error-invalid-token/22645/6 "2020-07-02T09:55:30Z")

</div>

Hi Tommy,

```
Thanks for reply, below is php code of integration, please review this code and let me know where I am doing wrong

require_once 'G:\php\xampp\htdocs\drupal-8.8.5\drupal-8.8.5\vendor\firebase\php-jwt\src\BeforeValidException.php';
require_once 'G:\php\xampp\htdocs\drupal-8.8.5\drupal-8.8.5\vendor\firebase\php-jwt\src\ExpiredException.php';
require_once 'G:\php\xampp\htdocs\drupal-8.8.5\drupal-8.8.5\vendor\firebase\php-jwt\src\SignatureInvalidException.php';
require_once 'G:\php\xampp\htdocs\drupal-8.8.5\drupal-8.8.5\vendor\firebase\php-jwt\src\JWT.php';

use \Firebase\JWT\JWT;
use Drupal\zoomapi;
use Drupal\Core\Controller\ControllerBase;

/**
 * Defines Zoom_meeting_controller class.
 */
class Zoom_meeting_controller extends ControllerBase {

  /**
   * Display the markup.
   *
   * @return array
   * Return markup array.
   */

private $zoom_api_key = 'key';
private $zoom_api_secret = 'key';

  public function start_meeting() {
    $zoom_meeting = new Zoom_meeting_controller();
try{
    $z = $zoom_meeting->createAMeeting(array(
'start_date'=>date("Y-m-d h:i:s", strtotime('tomorrow')),
'meetingTopic'=>'Example Test Meeting',
'timezone'=>'Asia/Tashkent',
'alternative_host_ids'=>''
));
print_r($z);
return $z;

} catch (Exception $ex) {
  echo $ex;
}

  }

public function createAMeeting( $data = array() ) {
  $post_time = $data['start_date'];
  $start_time = gmdate( "Y-m-d\TH:i:s", strtotime( $post_time ) );
  $createAMeetingArray = array();

  $alternative_host_ids='';

  $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'] : "";
  //echo "1..................";
  $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' => $alternative_host_ids
  );
  return $this->sendRequest($createAMeetingArray);
}

protected function sendRequest($data) {
$email="";
$request_url="https://api.zoom.us/v2/users/".$email."/meetings";
$jwt_token=$this->generateJWTKey();
//$jwt_token="token";
$headers = array(
"Authorization: Bearer ".$jwt_token,
"content-type: application/json"
);

$postFields = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_URL, $request_url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
$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 = "";
$secret = "";
$token = array(
"iss" => $key,
"exp" => time() + 3600 //60 seconds as suggested
);
echo "<br>";
return JWT::encode( $token, $secret );
}

}
?>
    
Thanks,
Jyoti
```

---

<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:** [July 6, 2020, 10:33pm UTC](https://devforum.zoom.us/t/jwt-token-is-not-working-giving-error-invalid-token/22645/7 "2020-07-06T22:33:18Z")

</div>

Hey @tiwari.jyoti.05,

I am not an expert in PHP so please try referencing PHP documentation or stack overflow.

You can also use one of the PHP libraries listed here to generate a JWT:

> **[JWT.IO](https://jwt.io/)**
>
> JSON Web Tokens are an open, industry standard RFC 7519 method for representing claims securely between two parties.

Thanks,  
Tommy

---

<div class="post-metadata">

**Author:** ![tiwari.jyoti.05](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/tiwari.jyoti.05/32/11152_2.png) [@tiwari.jyoti.05](https://devforum.zoom.us/u/tiwari.jyoti.05)\
**Post date:** [July 7, 2020, 7:11am UTC](https://devforum.zoom.us/t/jwt-token-is-not-working-giving-error-invalid-token/22645/8 "2020-07-07T07:11:37Z")

</div>

Hi Tommy,  
Thanks for help, now my code is working and I am able to create a meeting in Zoom from my application.

Thanks,  
Jyoti

---

<div class="post-metadata">

**Author:** ![sandipchavan1990](https://avatars.discourse-cdn.com/v4/letter/s/3be4f8/32.png) [@sandipchavan1990](https://devforum.zoom.us/u/sandipchavan1990)\
**Post date:** [July 7, 2020, 7:29am UTC](https://devforum.zoom.us/t/jwt-token-is-not-working-giving-error-invalid-token/22645/9 "2020-07-07T07:29:34Z")

</div>

Hi Jyoti,

Can you please help me with generating the access token. i’m facing the same issue.

Thanks in advance!!!

---

<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:** [July 9, 2020, 5:41pm UTC](https://devforum.zoom.us/t/jwt-token-is-not-working-giving-error-invalid-token/22645/10 "2020-07-09T17:41:16Z")

</div>

Happy to hear you got it working @tiwari.jyoti.05! 🙂

Thanks,  
Tommy

---

<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:** [July 9, 2020, 5:42pm UTC](https://devforum.zoom.us/t/jwt-token-is-not-working-giving-error-invalid-token/22645/11 "2020-07-09T17:42:15Z")

</div>

Hey @sandipchavan1990,

Please provide more details about your issue. If you are trying to generate a token in PHP, use one of the PHP libraries listed here:

> **[JWT.IO](https://jwt.io/)**
>
> JSON Web Tokens are an open, industry standard RFC 7519 method for representing claims securely between two parties.

Thanks,  
Tommy

---

<div class="post-metadata">

**Author:** ![tiwari.jyoti.05](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/tiwari.jyoti.05/32/11152_2.png) [@tiwari.jyoti.05](https://devforum.zoom.us/u/tiwari.jyoti.05)\
**Post date:** [July 22, 2020, 11:39am UTC](https://devforum.zoom.us/t/jwt-token-is-not-working-giving-error-invalid-token/22645/12 "2020-07-22T11:39:44Z")

</div>

Hi Tommy,

As I updated earlier now my code is working fine. thanks for help.

Thanks.

---

<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:** [July 24, 2020, 9:17pm UTC](https://devforum.zoom.us/t/jwt-token-is-not-working-giving-error-invalid-token/22645/13 "2020-07-24T21:17:22Z")

</div>

Great! Happy to hear you got it working! 🙂

Thanks,  
Tommy
