# Can someone please provide me PHP code for generating JWTKey

**URL:** <https://devforum.zoom.us/t/can-someone-please-provide-me-php-code-for-generating-jwtkey/12060>\
**Category:** API and Webhooks\
**Created:** [April 8, 2020, 5:35am UTC](https://devforum.zoom.us/t/can-someone-please-provide-me-php-code-for-generating-jwtkey/12060 "2020-04-08T05:35:00Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dora\_Reddy](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/dora_reddy/32/21698_2.png) [@Dora\_Reddy](https://devforum.zoom.us/u/Dora_Reddy)\
**Post date:** [April 8, 2020, 5:35am UTC](https://devforum.zoom.us/t/can-someone-please-provide-me-php-code-for-generating-jwtkey/12060/1 "2020-04-08T05:35:00Z")

</div>

Hello All,

I need php script for generating JWTKey for zoom API v2 integration.  
Can someone please provide me the script and their supporting files.

Thank you

---

<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:** [April 8, 2020, 8:08am UTC](https://devforum.zoom.us/t/can-someone-please-provide-me-php-code-for-generating-jwtkey/12060/2 "2020-04-08T08:08:32Z")

</div>

Hey @Dora_Reddy,

See the JWT Token generation sample PHP code here:

[https://marketplace.zoom.us/docs/guides/auth/jwt#sample-code](https://marketplace.zoom.us/docs/guides/auth/jwt#sample-code)

Thanks,  
Tommy

---

<div class="post-metadata">

**Author:** ![Dora\_Reddy](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/dora_reddy/32/21698_2.png) [@Dora\_Reddy](https://devforum.zoom.us/u/Dora_Reddy)\
**Post date:** [April 8, 2020, 10:25am UTC](https://devforum.zoom.us/t/can-someone-please-provide-me-php-code-for-generating-jwtkey/12060/3 "2020-04-08T10:25:08Z")

</div>

Thanks @tommy for the reply.

From the link i see PHP code below and it is used for Active Users from Zoom not for generateJWT token.

```auto
<?php

$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 39ug3j309t8unvmlmslmlkfw853u8",
    "content-type: application/json"
  ),
));

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

curl_close($curl);

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

```

Actually I’m expecting script for generating JWT token like below ( I don’t have complete script I found below piece of code in some other thread)

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 );  
}

---

<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:** [April 8, 2020, 7:41pm UTC](https://devforum.zoom.us/t/can-someone-please-provide-me-php-code-for-generating-jwtkey/12060/4 "2020-04-08T19:41:09Z")

</div>

Hey @Dora_Reddy,

Ah true, apologies. You can see sample PHP code and libraries for generating JWT tokens 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:** ![Dora\_Reddy](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/dora_reddy/32/21698_2.png) [@Dora\_Reddy](https://devforum.zoom.us/u/Dora_Reddy)\
**Post date:** [April 24, 2020, 12:41pm UTC](https://devforum.zoom.us/t/can-someone-please-provide-me-php-code-for-generating-jwtkey/12060/5 "2020-04-24T12:41:32Z")

</div>

@tommy I’m facing difficulty in generating JWT token through PHP Code.

So I’m generating JWT token from JWT app provided at [marketplace.zoom.us](http://marketplace.zoom.us) below  
[https://marketplace.zoom.us/develop/apps/E\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*n/credentials](https://marketplace.zoom.us/develop/apps/E ****************** n/credentials)

by having Expiration Time for a longer period of 2 years and saving the JWT token in our database.

Later on using the saved JWT token whenever i use Zoom API for creating meetings.

Will this work?

---

<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:** [April 28, 2020, 4:56pm UTC](https://devforum.zoom.us/t/can-someone-please-provide-me-php-code-for-generating-jwtkey/12060/6 "2020-04-28T16:56:36Z")

</div>

Hey @Dora_Reddy,

That will work, but it is more secure to generate the JWT Token for a shorter amount of time, each time you want to use it.

Did none of the helper libraries work from [jwt.io](http://jwt.io)?

Thanks,  
Tommy

---

<div class="post-metadata">

**Author:** ![Dora\_Reddy](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/dora_reddy/32/21698_2.png) [@Dora\_Reddy](https://devforum.zoom.us/u/Dora_Reddy)\
**Post date:** [April 29, 2020, 4:25pm UTC](https://devforum.zoom.us/t/can-someone-please-provide-me-php-code-for-generating-jwtkey/12060/7 "2020-04-29T16:25:20Z")

</div>

@tommy Thanks for the reply. I looked into [https://jwt.io/](https://jwt.io/) but it had many libraries. I’m confused to pick the correct one suitable for my requirement.

In this post [Help with api create meeting with php](https://devforum.zoom.us/t/help-with-api-create-meeting-with-php/5189) @mike1 posted below code for generating JWT but it didn’t have full code like JWT::encode function. Looking for full working code  
//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 );  
}

---

<div class="post-metadata">

**Author:** ![laurinkeithdavis](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/laurinkeithdavis/32/7533_2.png) [@laurinkeithdavis](https://devforum.zoom.us/u/laurinkeithdavis)\
**Post date:** [May 3, 2020, 3:45pm UTC](https://devforum.zoom.us/t/can-someone-please-provide-me-php-code-for-generating-jwtkey/12060/8 "2020-05-03T15:45:26Z")

</div>

Did you ever figure this out? I’m just now trying to make this work, but none of the libraries match up well to the Zoom API documentation.

---

<div class="post-metadata">

**Author:** ![Dora\_Reddy](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/dora_reddy/32/21698_2.png) [@Dora\_Reddy](https://devforum.zoom.us/u/Dora_Reddy)\
**Post date:** [May 3, 2020, 5:02pm UTC](https://devforum.zoom.us/t/can-someone-please-provide-me-php-code-for-generating-jwtkey/12060/9 "2020-05-03T17:02:58Z")

</div>

Still i didn’t found any solution. Let me know if you find any. Looking for 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:** [May 4, 2020, 11:34pm UTC](https://devforum.zoom.us/t/can-someone-please-provide-me-php-code-for-generating-jwtkey/12060/10 "2020-05-04T23:34:26Z")

</div>

Hey @Dora_Reddy, @laurinkeithdavis,

I would suggest using this library:

> **[firebase/php-jwt](https://github.com/firebase/php-jwt)**
>
> PHP package for JWT. Contribute to firebase/php-jwt development by creating an account on GitHub.

Thanks,  
Tommy

---

<div class="post-metadata">

**Author:** ![laurinkeithdavis](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/laurinkeithdavis/32/7533_2.png) [@laurinkeithdavis](https://devforum.zoom.us/u/laurinkeithdavis)\
**Post date:** [May 5, 2020, 2:53am UTC](https://devforum.zoom.us/t/can-someone-please-provide-me-php-code-for-generating-jwtkey/12060/11 "2020-05-05T02:53:35Z")

</div>

Yes, that is the one that I’m trying to use, but to no avail.

---

<div class="post-metadata">

**Author:** ![samly](https://avatars.discourse-cdn.com/v4/letter/s/a87d85/32.png) [@samly](https://devforum.zoom.us/u/samly)\
**Post date:** [May 5, 2020, 12:58pm UTC](https://devforum.zoom.us/t/can-someone-please-provide-me-php-code-for-generating-jwtkey/12060/12 "2020-05-05T12:58:22Z")

</div>

@laurinkeithdavis Can you provide a sample of how you’re trying to do it?

You can find a well-written write up here as well: [https://www.sitepoint.com/php-authorization-jwt-json-web-tokens/](https://www.sitepoint.com/php-authorization-jwt-json-web-tokens/)

---

<div class="post-metadata">

**Author:** ![laurinkeithdavis](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/laurinkeithdavis/32/7533_2.png) [@laurinkeithdavis](https://devforum.zoom.us/u/laurinkeithdavis)\
**Post date:** [May 6, 2020, 11:38am UTC](https://devforum.zoom.us/t/can-someone-please-provide-me-php-code-for-generating-jwtkey/12060/13 "2020-05-06T11:38:21Z")

</div>

I don’t know that posting any example I have so far would be helpful. I’m just trying to make the connection, I can’t even figure out what the parameters are supposed to be or how I generate the token.

> [@samly](#):
>
> You can find a well-written write up here as well: [https://www.sitepoint.com/php-authorization-jwt-json-web-tokens/](https://www.sitepoint.com/php-authorization-jwt-json-web-tokens/)

Read that one as well, and thanks, but still can’t figure it out. Is there not a working example of using the Zoom API in PHP? The one in the docs does not make sense ([https://marketplace.zoom.us/docs/guides/auth/jwt](https://marketplace.zoom.us/docs/guides/auth/jwt)) - what goes where in that sample?? What is the “Bearer”?

---

<div class="post-metadata">

**Author:** ![andrew4](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/andrew4/32/5296_2.png) [@andrew4](https://devforum.zoom.us/u/andrew4)\
**Post date:** [May 8, 2020, 11:21am UTC](https://devforum.zoom.us/t/can-someone-please-provide-me-php-code-for-generating-jwtkey/12060/14 "2020-05-08T11:21:09Z")

</div>

@laurinkeithdavis, I found the Zoom documentation lacking as well. Here’s an example of generating the token with **firebase/php-jwt** and **GuzzleHttp** (see code below).

This will generate a JWT token with a 5 second lifespan. Then, it will use the token to make a request to Zoom’s API with GuzzleHttp and list users on the account.

$api\_secret = “XXXXXX”;  
$api\_key = “XXXXXX”;  
$payload = array(  
“iss” =\> $api\_key,  
“exp” =\> (time() + 5)  
);  
$jwt = JWT::encode($payload, $api\_secret);

$client = new \GuzzleHttp\Client([‘headers’ =\> [‘authorization’ =\> 'Bearer '.$jwt]]);  
$response = $client-\>request(  
‘GET’,  
‘[https://api.zoom.us/v2/users](https://api.zoom.us/v2/users)’  
);

return json\_decode($response-\>getBody(), true);

---

<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:** [May 13, 2020, 11:14pm UTC](https://devforum.zoom.us/t/can-someone-please-provide-me-php-code-for-generating-jwtkey/12060/15 "2020-05-13T23:14:40Z")

</div>

Thanks for providing a solution @andrew4! 🙂

@laurinkeithdavis let me know if this helps!

As for what the “Bearer” is, that just let’s the Zoom API know what kind of authentication to expect. Here is the request header you want to provide when making requests to the Zoom API:

```json
{ "Authorization": "Bearer JWT_TOKEN_HERE" }

```

We will work on improving our JWT docs as soon as possible.

-Tommy

---

<div class="post-metadata">

**Author:** ![FutureX](https://avatars.discourse-cdn.com/v4/letter/f/58956e/32.png) [@FutureX](https://devforum.zoom.us/u/FutureX)\
**Post date:** [June 29, 2020, 9:22pm UTC](https://devforum.zoom.us/t/can-someone-please-provide-me-php-code-for-generating-jwtkey/12060/16 "2020-06-29T21:22:20Z")

</div>

I’ve also found this one aspect to be very lacking in documentation. All the documentation that I’ve found is way over complicated. I just need to generate a JWT on the fly before each API call. I thought I remember seeing a Postman sample embedded in a webpage to generate the JWT but now I can’t find that.

I would love to see the curl code to generate a JWT in a format like below. I’m initiating everything from Filemaker so if I have the below format I can take from there.

curl --request GET   
–url ‘[https://api.zoom.us/v2/users?status=active&page\_size=30&page\_number=1](https://api.zoom.us/v2/users?status=active&page_size=30&page_number=1)’   
–header ‘authorization: Bearer { your\_token }’   
–header 'content-type: application/json

```auto

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, 11:56pm UTC](https://devforum.zoom.us/t/can-someone-please-provide-me-php-code-for-generating-jwtkey/12060/17 "2020-06-30T23:56:19Z")

</div>

Hey @FutureX,

Thanks for your feedback on our docs, we will work on making it more clear.

> [@FutureX](#):
>
> I thought I remember seeing a Postman sample embedded in a webpage to generate the JWT but now I can’t find that.

You can generate a test JWT Token on your JWT App Credentials page in the Marketplace.

Here are the JWT generation docs with a link to see libraries we recommend:

[https://marketplace.zoom.us/docs/guides/auth/jwt](https://marketplace.zoom.us/docs/guides/auth/jwt)

Thanks,  
Tommy

---

<div class="post-metadata">

**Author:** ![FutureX](https://avatars.discourse-cdn.com/v4/letter/f/58956e/32.png) [@FutureX](https://devforum.zoom.us/u/FutureX)\
**Post date:** [July 1, 2020, 1:00am UTC](https://devforum.zoom.us/t/can-someone-please-provide-me-php-code-for-generating-jwtkey/12060/18 "2020-07-01T01:00:01Z")

</div>

Thanks for the response but that’s not what I’m looking for. I doing the credential generation from within Filemaker so it’s a basic URL call but I just need to see how the CURL is formatted similar to the sample in my last post.

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 1, 2020, 10:32pm UTC](https://devforum.zoom.us/t/can-someone-please-provide-me-php-code-for-generating-jwtkey/12060/19 "2020-07-01T22:32:32Z")

</div>

Hey @FutureX,

Do you mean like this?

```auto
curl --request GET
–url 'https://api.zoom.us/v2/users?status=active&page_size=30&page_number=1'
–header 'authorization: Bearer JWT_TOKEN_HERE'
–header 'content-type: application/json'

```

Thanks,  
Tommy

---

<div class="post-metadata">

**Author:** ![DeveloperBot](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/developerbot/32/12632_2.png) [@DeveloperBot](https://devforum.zoom.us/u/DeveloperBot)\
**Post date:** [August 21, 2020, 10:32pm UTC](https://devforum.zoom.us/t/can-someone-please-provide-me-php-code-for-generating-jwtkey/12060/20 "2020-08-21T22:32:27Z")

</div>


