Forums

Simple ZoHo CRM Howto

lowrykun 07 Jun, 2012
I looked in the forum and didn't see a working example of how to post information from a Chronoform to ZoHo. I came up with a really simple way of doing it using the new Authentication Token.

On the OnSubmit Event add a Custom Code action.

<?php
//Get your auth code through the ZoHo
$auth = 'YOUR AUTH CODE';

//This is a very basic lead. See https://zohocrmapi.wiki.zoho.com/insertRecords-Method.html#Sample_Lead_XMLDATA
$xml = '<Leads>
<row no="1">
<FL val="Lead Source">Website</FL>
<FL val="First Name">'.$form->data['first_name'].'</FL>
<FL val="Last Name">'.$form->data['last_name'].'</FL>
<FL val="Email">'.$form->data['email'].'</FL>
</row>
</Leads>';

//Initialize connection
$ch = curl_init('https://crm.zoho.com/crm/private/xml/Leads/insertRecords');
curl_setopt($ch, CURLOPT_VERBOSE, 1);//standard i/o streams
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);// Turn off the server and peer verification
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//Set to return data to string ($response)
curl_setopt($ch, CURLOPT_POST, 1);//Regular post
//Set post fields
$query = "authtoken={$auth}&scope=crmapi&xmlData={$xml}";
curl_setopt($ch, CURLOPT_POSTFIELDS, $query);// Set the request as a POST FIELD for curl.
//Execute cUrl session
$response = curl_exec($ch);
curl_close($ch);
?>


That's it! With a valid token this should submit the contact's First Name, Last Name, Email, and Lead Source.
Max_admin 19 Jun, 2012
Thanks for the short tutorial!🙂

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
brianp22 28 Aug, 2012
Wow that is great, Thanks 🙂
jstec 04 Oct, 2012
Is this broken now? I cannot get it to work and I'm not very familiar with debugging cUrl. Adding a debug option to OnSubmit is not showing me what is going on in the Custom Code block. 😟

I know my Auth Code is good because I can drive the insertion into Zoho from my browser.
GreyHead 04 Oct, 2012
Hi jstec,

This should still work as far as I know, nothing significant has changed. I don't have a Zoho account to check anything though.

You should see debug information if you add a debugger action and turn on debug in the cURL action. You may just get a simple message - or possibly a whole HTML page depending on the way that Zoho works.

Bob
jstec 04 Oct, 2012
Thanks for your help.

All I see in the ChronoForms debugger info is the data array for the form, and a data validation array that is empty (no errors?). I do not see any cUrl debugging info at all, even though the code has CURLOPT_VERBOSE set to 1. AS I said, I'm not familiar with debugging cUrl, so if you could give me step-by-step (or a pointer to same), I'd appreciate it.
GreyHead 05 Oct, 2012
Hi jstec,

Unfortunately there is no step by step process to follow. With cURL the default settings (the curlopts) work much of the time. If they don't then it becomes a quite complex process to debug and work out what is needed. This is because you have to understand the requirements of the site you are sending data too as well as the Joomla! end.

You might get more useful information if you switch to try my custom cURL [GH] action. This has more debugging code and also more flexible settings.

Bob
This topic is locked and no more replies can be posted.