Integrating With a 3rd party CRM Sofware

Customer Relationship Management (CRM) is an approach to managing a company's interaction with current and potential future customers. How do we manage those interactions you ask - using a software. There are bunch of CRM products out in the internet, but my top picks consist of Salesforce, Insightly and Zoho. In this tutorial we are going to focus on the last one.

About Zoho CRM

Zoho is a SaaS-based CRM software solution designed to manage sales, marketing, contacts, customer support and other business functions. Unlike the other premium CRMs we listed in the first paragraph, Zoho is distinguished by the fact that it is free while having up to 10 users.

Integrating Zoho CRM with Route4Me

Once you turn your leads to contacts you are ready to integrate them into the business. In this tutorial we will export contacts to the Route4Me Address Book using the Zoho API and Route4Me PHP SDK.

Contact screen of Zoho CRM

All you need is to use Get Contact method from the Zoho API and 2 methods from the Route4Me API - Forward Geocoding and Create a Location

Platform Method Endpoint HTTP Metod
Zoho Get Contact https://crm.zoho.com/crm/private/xml/Contacts/getRecords GET
Route4Me Forward Geocoding https://www.route4me.com/api/geocoder.php POST
Route4Me Create a Location https://www.route4me.com/api.v4/address_book.php POST

Retrieving Data from Zoho CRM

Retrieving data from Zoho is really easy as long as the api is well documented. This is how to retrieve contacts:

Note
GET /contacts
1 $endpoint = 'https://crm.zoho.com/crm/private/xml/Contacts/getRecords';
2 
3 $params = array(
4  "authtoken" => $auth_token
5  "scope" => "crmapi"
6  "selectColumns" => 'All'
7  );
8 
9 $url = $endpoint . '?' . http_build_query($params);
10 
11 $ch = curl_init();
12 curl_setopt($ch, CURLOPT_URL, $url);
13 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
14 curl_setopt($ch, CURLOPT_TIMEOUT, 30);
15 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
16 $response = curl_exec($ch);
17 curl_close($ch);
18 
19 $xmlResponse = new SimpleXMLElement($response);

If everything was alright, xml returned will look like this:

1 <Contacts>
2 <row no="1">
3 <FL val="CONTACTID">2140511000000108188</FL>
4 <FL val="SMOWNERID">2140511000000107005</FL>
5 <FL val="Contact Owner">Vale Gucci</FL>
6 <FL val="Lead Source">Advertisement</FL>
7 <FL val="First Name">John</FL>
8 <FL val="Last Name">Doe</FL>
9 <FL val="ACCOUNTID">2140511000000108184</FL>
10 <FL val="Account Name">Initial acount</FL>
11 <FL val="Email">[email protected]</FL>
12 <FL val="Title">JDoe inc.</FL>
13 <FL val="Phone">123456</FL>
14 <FL val="Home Phone">888</FL>
15 <FL val="Fax">963</FL>
16 <FL val="Mobile">111222333</FL>
17 <FL val="Date of Birth">1992-10-29</FL>
18 <FL val="SMCREATORID">2140511000000107005</FL>
19 <FL val="Created By">Vale Gucci</FL>
20 <FL val="MODIFIEDBY">2140511000000107005</FL>
21 <FL val="Modified By">Vale Gucci</FL>
22 <FL val="Created Time">2016-10-10 08:09:12</FL>
23 <FL val="Modified Time">2016-10-10 08:09:12</FL>
24 <FL val="Mailing Street">40 Mercer St, New York, NY 10013, USA</FL>
25 <FL val="Mailing City">New York</FL>
26 <FL val="Mailing State">New York</FL>
27 <FL val="Mailing Zip">10013</FL>
28 <FL val="Mailing Country">USA</FL>
29 <FL val="Description">Mr. John doe is our loyal customer</FL>
30 <FL val="Email Opt Out">false</FL>
31 <FL val="Skype ID">monteecristo</FL>
32 <FL val="Salutation">Mr.</FL>
33 <FL val="Last Activity Time">2016-10-10 08:09:12</FL>
34 <FL val="Twitter">vale</FL>
35 </row>
36 </Contacts>

Sending Data to Route4Me

Once you finished gathering data from the above response, you're ready to send them to Route4Me. For this to complete we need to geocode address and then to send it along with the other data using Create a Location method.

Geocoding an address

As long as we need to pin the contact on the map, we need to geocode its address, in other words we want to get latitude and longitude out of the address.

1 <?php
2  namespace Route4Me;
3 
4  $vdir=$_SERVER['DOCUMENT_ROOT'].'/route4me/examples/';
5 
6  require $vdir.'/../vendor/autoload.php';
7 
8  use Route4Me\Route4Me;
9  use Route4Me\Route;
10 
11  // Set the api key in the Route4me class
12  Route4Me::setApiKey('11111111111111111111111111111111');
13 
14  $geocodingParameters=array(
15  'format' => 'xml',
16  'addresses' => '40+Mercer+St%2C+New+York%2C+NY+10013%2C+USA'
17  );
18 
19  $fGeoCoding = new Geocoding();
20 
21  $fgResult = $fGeoCoding->forwardGeocoding($geocodingParameters);
22 ?>

What we do up there in the code block is that we send an address to Route4Me API providing access to only valid API Key and tell it to return response in the xml format. If everything was alright, you can expect the following response:

1 <?xml version="1.0" encoding="UTF-8" ?>
2  <destinations>
3  <destination
4  destination="40 Mercer St, New York, NY 10013, USA"
5  lat="40.7212093"
6  lng="-74.0009378"
7  type="street_address"
8  confidence="high"
9  original="40+Mercer+St%2C+New+York%2C+NY+10013%2C+USA"
10  />
11  </destinations>

With this response we are getting valid address, latitude and longitude. And we are on the next step.

Creating a Location

Now that we geocoded the contact address we can pass it to the "Create a Location" method along with other data.

1 <?php
2  namespace Route4Me;
3 
4  $vdir=$_SERVER['DOCUMENT_ROOT'].'/route4me/examples/';
5  require $vdir.'/../vendor/autoload.php';
6 
7  use Route4Me\Route4Me;
8  use Route4Me\Route;
9 
10  // Set the api key in the Route4me class
11  Route4Me::setApiKey('11111111111111111111111111111111');
12 
13  $AdressBookLocationParameters=AddressBookLocation::fromArray(array(
14  "address_group":"Zoho CRM Contacts",
15  "address_alias":"Bowman and Co",
16  "address_1":"40 Mercer St, New York, NY 10013, USA",
17  "cached_lat":"40.7212093",
18  "cached_lng":"-74.0009378",
19  "first_name":"John",
20  "last_name":"Doe",
21  "address_email":"[email protected]",
22  "address_phone_number":"123456",
23  "address_city":"New York",
24  "address_zip":"10013",
25  "address_custom_data":{
26  "Contact ID": "2140511000000108188",
27  "Date of Birth": ">1992-10-29",
28  "salutation": "Mr.",
29  "Lead Source": "Advertisement"
30  }
31  ));
32 
33  $abContacts=new AddressBookLocation();
34 
35  $abcResults=$abContacts->addAdressBookLocation($AdressBookLocationParameters);
36 
37 
38 ?>
Exported Zoho contact in Route4Me

Conclusion

In this tutorial we learned how to send Zoho contact to Route4Me. You might consider other integrations too, for example sending orders to Route4Me, Attaching CRM products and invoices to route addresses... And you can do the integration vice versa - ex. Sending Route4Me address book contacts to Zoho, creating CRM events before starting a route, Sending a report to CRM when a route is completed...

Useful links: