how to integrate zoho api in php laravel
1) Go to the Zoho Developer Console. If it’s the first time you’re registering a client application, click GET STARTED.
Choose the required Client Type.
2) Request Authorization Code
https://www.zylker.com/callback?code=1000.xxxxxxxxe1a88.xxxxxxxx40a3&location=us&accounts-server=https%3A%2F%2Faccounts.zoho.com
This API will return the short-lived grant token that will be required to generate the access and refresh tokens. Remember The authorization code will be valid for 1 minute.
3) Generate access token
https://accounts.zoho.com/oauth/v2/token?grant_type=authorization_code&code=1000.xxxxxxd34d.xxxxxxx909a&client_id=1000.xxxxxxxxxxHF2C6H&redirect_uri=https://www.zylker.com/callback&client_secret=xxxxxxxxx4f4f7a"
This API will return the following response
{ "access_token": "1000.8cb99dxxxxxxxxxxxxx9be93.9b8xxxxxxxxxxxxxxxf", "refresh_token": "1000.3ph66exxxxxxxxxxxxx6ce34.3c4xxxxxxxxxxxxxxxf", "api_domain": "https://www.zohoapis.com", "token_type": "Bearer", "expires_in": 3600 }
4) Refresh the Access Token
Now We do not need to create an access token using the Authorization code. Because authorization will be valid for 1 minute. So in the next API, we will use a refresh token for the access token. Check below API request:-
$curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://accounts.zoho.com/oauth/v2/token?grant_type=refresh_token&client_id=1000.DOMMsdfsdfsdfsdfsdf&client_secret=55b12esdfsdfdsacc57sdf7fe42ac8839c9d&redirect_uri=https%3A%2F%2Fwww.google.com&refresh_token=1000.352sdfsdfsdfsdfsdfsfsdfsdf96ec9e5829680af240dad3eaed99b", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_HTTPHEADER => array( "cache-control: no-cache", "postman-token: 904023ab-9646-e258-6d6c-b8a44ee3d765" ), )); $response = curl_exec($curl); $err = curl_error($curl); // curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { $data = json_decode($response); print_r($data->access_token);
This API return below Response:-
{ "access_token": "1000.6jh82dxxxxxxxxxxxxx9be93.9b8xxxxxxxxxxxxxxxf", "expires_in": 3600, "api_domain": "https://www.zohoapis.com", "token_type": "Bearer" }
5) Push data to ZOHO form
Check below code snippet to push data to Zoho form
$curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'https://creator.zoho.com/api/v2/jason18/zylker-store/form/FORM_NAME_HERE', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS =>'{ "data": { "Email": "testing02@gmail.com", "Category": "DIESEL ENGINES", "Last_Contact": "kl", "Time": "00:30:33", "Supplier_Name": "shweta" } }', CURLOPT_HTTPHEADER => array( 'Authorization: Zoho-oauthtoken 1000.f2sdfjkshdjkfhsjkdhfjkshdfjkhsd633602c7', 'Content-Type: application/json', 'Cookie: 442b5845d7=2b41bd7718eb8afe5523fda24f347c1a; JSESSIONID=91FA31f4f4f492627F2F06655; _zcsr_tmp=c01373c0-3d8a-40b5-b42e-ddc19ec20d07; c3a98dd0f1=665270c94562f4f4f4f4f4df07; zccpn=c01373c0-3d8a-40b5-b42e-ddc19ec20d07' ), )); $response = curl_exec($curl); curl_close($curl); echo $response;
Please share the article