Take note that the grant token will only last for 3 to 10 minutes depending on what you select when you use one of these methods. The grant token can be gotten by either using the self-client in the developer console or going to the specific url listed in the documentation. $oAuthTokens = $oAuthClient->generateAccessToken($grantToken) $oAuthClient = ZohoOAuth::getClientInstance() Here is the code I used to get these tokens: The Access and Refresh tokens only need to be gotten once per user and since I’m the only user, then I only have to do this once to add the tokens to the zcrm_oauthtokens.txt file. Persistence_handler_class=ZohoOAuthPersistenceHandler Token_persistence_path=/home/example/zoho/persistence The access_type should be offline and the persistance_handler_class should be ZohoOAuthPersistenceHandler. The token_persistence_path should be the path to the new file you created without the file name – just the path. The redirect_uri in the configuration file should match the redirect_uri used on the developer console app setup as well and should be the name of the script that will be making the api calls. This is documented fairly well in the zoho api documentation. The oauth_configuration file needs to have the client_id and the client_secret from the zoho developer console where you set up the app. These are in the vendor/zohocrm/php-sdk/src/resources folder. My configuration file looks like other configuration file is the oauth_configuration.properties file in the same location as the first configuration file. You need to set the currentUserEmail to the email address of the user email of the Zoho account that’s used for creating the grant token. I haven’t gotten anything to show up in this file yet, but I’ll update this post when and if I do. I created the application log file by creating a ZCRMClientLibrary.log and then putting the path to that file in the configuration file. Not sure why, but the code only worked when setting this to false. I first set the sandbox to true, but this didn’t work well for me. There are two configuration files in the SDK. I could not get it to work until I created this empty file. To make this work correctly, I had to create a persistence file named zcrm_oauthtokens.txt and leave it empty (it’s important that it’s named exactly that). The database seemed like overkill just to handle the access and refresh tokens. Since I don’t have a lot of users and I didn’t want to set up another database for my clients site, the file seems to be our best option. I decided to use the file handler instead of a database for persistence I decided to use the PHP SDK just to take advantage of their persistence handler. However, once I finally figured out how to do OAuth using the API without the SDK, I realized that I would have to write a lot of code to handle the persistence of the grant, access and refresh tokens. I am usually pretty good at learning API’s using JSON or XML. I just need to insert a couple of leads and vendors and pull some emails from their current contacts, so learning the SDK when seemed like overkill. I was going to use the PHP SDK at first, but I don’t have a lot of work to do with this API. I decided to use the PHP SDK to take advantage of the persistence handler Hopefully, this will save someone else some time. I had a hard time getting the authentication to work, so I thought I would write about what I found to work in the end. This is custom code for one client to be used to integrate their website with their zoho account. In other words, I am not writing a plugin to be used by multiple clients with different login information. The API’s I’ve worked with in the past may have had an OAuth option, but usually, there was another option available if using the API for ourselves with our own account. Version 2.0 of the Zoho API uses OAuth for authentication which is not something I have used often, if ever. Now, they’ve deprecated that API version and will stop supporting it soon, so I must upgrade to version 2 of the API. A year or two ago I did some work for a client with the Zoho API version 1.0.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |