Skip to content

mctekk/zohocrm

Repository files navigation

Zoho CRM library for PHP

The Zoho CRM library is a simple wrapper around Zoho API

At MC we work a lot with Zoho and we found ourself repeating the same patter over and over that's why we build this library.

Installation

Using composer, execute the following command to add the requirement to your composer.json

$ composer require mctekk/zohocrm:^0.1

Let's start

Zoho API V2 has change the wey they handle connecto to the API, it now uses OAuth instead of just simple private and public keys. So you will have to do the following things to get this package to work with your app

Todo In future version we will add the refresh_token generator directly as a php script

<?php

use Zoho\CRM\ZohoClient;

$ZohoClient = new ZohoClient(); // Make the connection to zoho api
$ZohoClient->setAuthRefreshToken(getenv('ZOHO_AUTH_REFRESH_TOKEN'));
$ZohoClient->setZohoClientId(getenv('ZOHO_CLIENT_ID'));
$ZohoClient->setZohoClientSecret(getenv('ZOHO_CLIENT_SECRET'));
$refresh = $ZohoClient->generateAccessTokenByRefreshToken();
//or with redis $ZohoClient->manageAccessTokenRedis($redis);

$this->zohoClient->setModule('Leads');

$lead = new Lead();

$leadRequest = [
	'First_Name' => 'Test',
	'Last_Name' => 'Zoho',
	'Phone' => '000000000',
	'Email' => '[email protected]'
];

$response = $this->zohoClient->insertRecords(
	$leadRequest,
	['wfTrigger' => 'true']
);

$response->getResponseData();

The above values of the $request array can be taken from POST if you are using forms in landing page :D, just be sure that all the keys(name of the field on html) in the array have to be valid properties in the entity Lead of zoho, default properties can be found on documentation here or make sure that those properties exist in your account if you custom your Lead on Zoho; the following convention are made:

  • Name of fields are not CamelCase.
  • Name with space between words, space is substituted by an "_".
  • Need to clean(unset) from the array all the values that are not part of the entity, if you don't wanna make this, create another clean array.

Users of the .eu domain (i.e. your CRM URL is crm.zoho.eu, rather than crm.zoho.com) should call setEuDomain() after instantiating ZohoClient, i.e.

$ZohoClient = new ZohoClient(); // Make the connection to zoho api
$ZohoClient->setAuthRefreshToken(getenv('ZOHO_AUTH_REFRESH_TOKEN'));
$ZohoClient->setZohoClientId(getenv('ZOHO_CLIENT_ID'));
$ZohoClient->setZohoClientSecret(getenv('ZOHO_CLIENT_SECRET'));
$refresh = $ZohoClient->generateAccessTokenByRefreshToken();
$ZohoClient->setEuDomain();
$ZohoClient->setModule('Leads'); // Set the module