# Server-to-Server Access Token Expired

**URL:** <https://devforum.zoom.us/t/server-to-server-access-token-expired/81145>\
**Category:** API and Webhooks\
**Tags:** server-to-server\
**Created:** [January 9, 2023, 4:33am UTC](https://devforum.zoom.us/t/server-to-server-access-token-expired/81145 "2023-01-09T04:33:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![aeromir](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/aeromir/32/43832_2.png) [@aeromir](https://devforum.zoom.us/u/aeromir)\
**Post date:** [January 9, 2023, 4:33am UTC](https://devforum.zoom.us/t/server-to-server-access-token-expired/81145/1 "2023-01-09T04:33:37Z")

</div>

My server 2 server access token expired recently.

I’m trying to write some PHP code to get a new access token. On this page:

[https://marketplace.zoom.us/docs/guides/build/server-to-server-oauth-app/](https://marketplace.zoom.us/docs/guides/build/server-to-server-oauth-app/)

You say to use this curl command:

```auto
curl -X POST -H 'Authorization: Basic Base64Encoder(clientId:clientSecret)' https://zoom.us/oauth/token?grant_type=account_credentials&account_id={accountId}

```

I’ve tried this but it’s returning a 405 Method Not Allowed error.

$ch = curl\_init();

curl\_setopt($ch, CURLOPT\_URL, “[https://zoom.us/oauth/token?grant\_type=account\_credentials&account\_id=xxxxxxxxxxxxxxxxx](https://zoom.us/oauth/token?grant_type=account_credentials&account_id=xxxxxxxxxxxxxxxxx)”);  
curl\_setopt($ch, CURLOPT\_RETURNTRANSFER, 1);

// Set the Authorization header  
$auth = “Basic Base64Encoder(” . base64\_encode(“yyyyyyyyyyyyyyyyyyy:zzzzzzzzzzzzzzzzzzzzzzzzzz”). “)”;  
curl\_setopt($ch, CURLOPT\_HTTPHEADER, array(“Authorization: $auth”));

$output = curl\_exec($ch);

curl\_close($ch);

echo $output;

What’s the correct way to use php to call your api to get a new server 2 server access token?

---

<div class="post-metadata">

**Author:** ![aeromir](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/aeromir/32/43832_2.png) [@aeromir](https://devforum.zoom.us/u/aeromir)\
**Post date:** [January 9, 2023, 4:38am UTC](https://devforum.zoom.us/t/server-to-server-access-token-expired/81145/2 "2023-01-09T04:38:48Z")

</div>

I added this to the curl commands:

curl\_setopt($ch, CURLOPT\_POST, 1);

Now I get this error:  
{“status”:false,“errorCode”:-1,“errorMessage”:“Illegal base64 character 28”,“result”:null}

---

<div class="post-metadata">

**Author:** ![aeromir](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/aeromir/32/43832_2.png) [@aeromir](https://devforum.zoom.us/u/aeromir)\
**Post date:** [January 9, 2023, 4:43am UTC](https://devforum.zoom.us/t/server-to-server-access-token-expired/81145/3 "2023-01-09T04:43:18Z")

</div>

OK… got it working. Hopefully this helps someone:

$ch = curl\_init();

curl\_setopt($ch, CURLOPT\_URL, “[https://zoom.us/oauth/token?grant\_type=account\_credentials&account\_id=XXXXXXXXXXXXXX](https://zoom.us/oauth/token?grant_type=account_credentials&account_id=XXXXXXXXXXXXXX)”);  
curl\_setopt($ch, CURLOPT\_RETURNTRANSFER, 1);  
curl\_setopt($ch, CURLOPT\_POST, 1);

// Set the Authorization header  
$auth = "Basic " . base64\_encode(“yyyyyyyyyyyyyyyyyy:zzzzzzzzzzzzzzzzzzzzzz”);  
curl\_setopt($ch, CURLOPT\_HTTPHEADER, array(“Authorization: $auth”));

$output = curl\_exec($ch);

curl\_close($ch);

echo $output;

---

<div class="post-metadata">

**Author:** ![elisa.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/elisa.zoom/32/47836_2.png) [@elisa.zoom](https://devforum.zoom.us/u/elisa.zoom)\
**Post date:** [January 9, 2023, 10:20pm UTC](https://devforum.zoom.us/t/server-to-server-access-token-expired/81145/4 "2023-01-09T22:20:07Z")

</div>

Hey @aeromir  
Happy to hear that you got it to work and thanks for sharing your solution with the community!  
This is extremely valuable!

Cheers!  
Elisa

---

<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:** [January 13, 2024, 1:56pm UTC](https://devforum.zoom.us/t/server-to-server-access-token-expired/81145/5 "2024-01-13T13:56:37Z")

</div>

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