Created
June 30, 2022 10:58
-
-
Save rajurayhan/cf70172bc5466d2ee02609c8d876c186 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Support\Facades\Route; | |
use Illuminate\Support\Facades\Http; | |
use GuzzleHttp\Client as GuzzleClient; | |
/* | |
|-------------------------------------------------------------------------- | |
| Web Routes | |
|-------------------------------------------------------------------------- | |
| | |
| Here is where you can register web routes for your application. These | |
| routes are loaded by the RouteServiceProvider within a group which | |
| contains the "web" middleware group. Now create something great! | |
| | |
*/ | |
Route::get('/', function () { | |
$clientID = '1000.0Y5YJZWA68JKIGQQF1R4ZYINQ5K9VD'; | |
$requestBody = [ | |
'scope' => 'ZohoBooks.contacts.READ', | |
'client_id' => $clientID, | |
'response_type' => 'code', | |
'redirect_uri' => route('redirect') | |
]; | |
$redirectURL = 'https://accounts.zoho.com/oauth/v2/auth?'.http_build_query($requestBody); | |
return redirect()->away($redirectURL); | |
}); | |
Route::get('/redirect', function () { | |
// Get Token | |
$requestBody = [ | |
'code' => request()->code, | |
'client_id' => '1000.0Y5YJZWA68JKIGQQF1R4ZYINQ5K9VD', | |
'client_secret' => '2c04965cfb5025646a68992552c7666685a7c3d321', | |
'scope' => 'ZohoBooks.contacts.READ', | |
'grant_type' => 'authorization_code', | |
'redirect_uri' => route('redirect') | |
]; | |
$client = new GuzzleClient(); | |
$api = 'https://accounts.zoho.com/oauth/v2/token?'.http_build_query($requestBody); | |
$response = $client->request('POST', $api); | |
$response = $response->getBody()->getContents(); | |
$data = json_decode($response); | |
// Get Customers | |
$headers = [ | |
'Authorization' => 'Zoho-oauthtoken '.$data->access_token, | |
]; | |
$client = new GuzzleClient([ | |
'headers' => $headers | |
]); | |
$requestBody = [ | |
'organization_id' => 783349236 | |
]; | |
$api = 'https://books.zoho.com/api/v3/contacts?'.http_build_query($requestBody); | |
$response = $client->request('GET', $api); | |
$response = $response->getBody()->getContents(); | |
$customerData = json_decode($response); | |
return $customerData; | |
})->name('redirect'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment