Skip to content

Instantly share code, notes, and snippets.

@aorborc
Last active October 18, 2023 12:09
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aorborc/e7e9df4120e0e19b389ca985bc6842f8 to your computer and use it in GitHub Desktop.
Save aorborc/e7e9df4120e0e19b389ca985bc6842f8 to your computer and use it in GitHub Desktop.
Create Access Token using Zoho Creator API V2 and add record using PHP. Youtube Tutorial at https://www.youtube.com/watch?v=UqSsP-wz-mE
<?php
$client_id ='1000.GUPPSEH1013UZQA5SN8OAJV1DQU5FM';//Enter your Client ID here
$client_secret = '4932018fd429a4246e96d9186e77704d88d05b052a';//Enter your Client Secret here
$code = '1000.bf0e3723d718ac74660843a2128946b8.c6a7d9ce01ea879a22803f5f88bb0a6c';//Enter your Code here
$base_acc_url = 'https://accounts.zoho.com';
$service_url = 'https://creator.zoho.com';
$refresh_token = '1000.4f4b206a80c5e3e48c1cf3a55994a19c.c7c25dc7144da53c497b2d2ca834d1d0'; //Replce this with your Refresh token
$token_url = $base_acc_url . '/oauth/v2/token?grant_type=authorization_code&client_id='. $client_id . '&client_secret='. $client_secret . '&redirect_uri=http://localhost&code=' . $code;
//generate_refresh_token($token_url);
function generate_access_token($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
$result = curl_exec($ch);
curl_close($ch);
return json_decode($result)->access_token;
}
$access_token_url = $base_acc_url . '/oauth/v2/token?refresh_token='.$refresh_token.'&client_id='.$client_id.'&client_secret='.$client_secret .'&grant_type=refresh_token';
$access_token = generate_access_token($access_token_url);
var_dump($access_token);
create_record($access_token);
function create_record($access_token){
$service_url = $GLOBALS['service_url'] . '/api/v2/rubenaorborc/contact-php-v2/form/Contact';
//Authorization: Zoho-oauthtoken access_token
$data = array('data' => array('Name' => 'Ruben', 'Email' => 'zoho@aorborc.com') );
$header = array(
'Authorization: Zoho-oauthtoken ' . $access_token,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $service_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$result = curl_exec($ch);
curl_close($ch);
var_dump($result);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment