Skip to content

Instantly share code, notes, and snippets.

@UVLabs
Created August 31, 2023 17:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save UVLabs/413a1c21c3a1d80e4c013f40a05cd8e3 to your computer and use it in GitHub Desktop.
Save UVLabs/413a1c21c3a1d80e4c013f40a05cd8e3 to your computer and use it in GitHub Desktop.
Example PHP script for generating access token and refresh token for Zoho APIs.
<?php
$api_url = "https://accounts.zoho.com/oauth/v2/token";
$content_type = "application/x-www-form-urlencoded";
$code = "1000.7c7b9fa2259fac74331e0045d4bf24b2.7de27ed34xxxxxxxxxxxx"; //Generated with a max of 10 min life from https://api-console.zoho.com for example scope: ZohoCRM.modules.ALL
$redirect_uri = "https://example.com/zoho.php"; // When testing on Localhost with PHP local server like: php -S localhost:8080 you can set the redirect URL as the same localhost root url example: http://localhost:8080/
// Live client
// $client_id = "1000.xxx..."; //Static Client ID from https://api-console.zoho.com
// $client_secret = "c3dxxx..."; //Static Client Secret from https://api-console.zoho.com
// Self client
$client_id = "1000.6HP6LPT5xxxxxxxxxxxx"; //Static Client ID from https://api-console.zoho.com
$client_secret = "f2c8cf608xxxxxxxxxxx"; //Static Client Secret from https://api-console.zoho.com
$grant_type = "authorization_code"; //Hard Coded
$access_type = "offline"; //Hard Coded
$curl = curl_init();
$post_data = array(
'code' => $code,
'redirect_uri' => $redirect_uri,
'client_id' => $client_id,
'client_secret' => $client_secret,
'grant_type' => $grant_type,
'access_type' => $access_type
);
curl_setopt($curl, CURLOPT_URL, $api_url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type' => $content_type));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
$response = curl_exec($curl);
curl_close($curl);
$response = json_decode($response);
echo "<pre>";
print_r($response);
echo "</pre>";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment