user3769145
user3769145

Reputation: 116

Upgrade from Zoho APIv1 to APIV2 -> requests are not saving data

I am in the process of upgrading my customer's site from Zoho's end of life v1 API to it's new v2 API.

I have followed the guide and I am not able to have requests to create a new 'Lead' save in the Zoho system.

I have the v2 API installed 'correctly' (no errors and it authenticates correctly) but go to insert a new lead.

Running the v1 code works so I believe the account is OK still. It is on a test domain but I have not seen anywhere that this might restrict this.

The v1 API Code:

$xml  = '<?xml version="1.0" encoding="UTF-8"?>'; // same error with or without this line
$xml .= '<Leads>';
$xml .= '<row no="1">';
$xml .= '<FL val="Lead Owner">'.'[email protected]'.'</FL>';
$xml .= '<FL val="First Name">'.$_POST['enquiry-firstname'].'</FL>';
$xml .= '<FL val="Last Name">'.$_POST['enquiry-lastname'].'</FL>';
$xml .= '<FL val="Email">'.$_POST['enquiry-email'] .'</FL>';
$xml .= '<FL val="Company">'.$_POST['enquiry-company'].'</FL>';
$xml .= '<FL val="Lead Source">Web Site</FL>';
$xml .= '<FL val="Phone">'.$_POST['enquiry-phone'].'</FL>';
$xml .= '<FL val="Description">
            Enquiry Type: ' . htmlentities($_POST['enquiry-enquiry'], ENT_QUOTES | ENT_IGNORE, "UTF-8") . '
            Message: '.htmlentities($_POST['enquiry-message'], ENT_QUOTES | ENT_IGNORE, "UTF-8") . '
            Board: ' . $zoho_descr;
$xml .= '</FL>';
$xml .= '</row>';
$xml .= '</Leads>';

$url ="https://crm.zoho.com/crm/private/xml/Leads/insertRecords";
$query="authtoken=<secret>&scope=crmapi&newFormat=1&xmlData=".$xml;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $query);// Set the request as a POST FIELD for curl.

$response = curl_exec($ch);
curl_close($ch);

Which I have modified to work in the v2: ** EDIT ** Changed this to match the documentatio. Field values changed to API value.

require_once('vendor/autoload.php');

ZCRMRestClient::initialize();

try {
    $moduleIns = ZCRMRestClient::getInstance()->getModuleInstance("Leads");

    $leads = array();

    $lead = ZCRMRecord::getInstance("Leads", null);
    $lead->setFieldValue("Owner", "[email protected]");
    $lead->setFieldValue("First_Name", $_POST['enquiry-firstname']);
    $lead->setFieldValue("Last_Name", $_POST['enquiry-lastname']);
    $lead->setFieldValue("Email", $_POST['enquiry-email']);
    $lead->setFieldValue("Company", $_POST['enquiry-company']);
    $lead->setFieldValue("Lead_Source", "Web Site");
    $lead->setFieldValue("Phone", $_POST['enquiry-phone']);
    $lead->setFieldValue("Description",  "Enquiry Type: " . htmlentities($_POST['enquiry-enquiry'], ENT_QUOTES | ENT_IGNORE, "UTF-8") . ' Message: '.htmlentities($_POST['enquiry-message'], ENT_QUOTES | ENT_IGNORE, 'UTF-8') . '  Board: ' . $zoho_descr);
    array_push($leads, $lead);

    $responseIn = $moduleIns->createRecords($records);

    foreach($responseIn->getEntityResponses() as $responseIns){
        echo "HTTP Status Code:".$responseIn->getHttpStatusCode();
        echo "Status:".$responseIns->getStatus();
        echo "Message:".$responseIns->getMessage();
        echo "Code:".$responseIns->getCode();
        echo "Details:".json_encode($responseIns->getDetails());
    }       
    echo "<pre>";
    var_dump($responseIn);
    echo "</pre>";
    die("Should be fine");
} catch (ZCRMException $e) {
    echo $e->getCode();
    echo $e->getMessage();
    echo $e->getExceptionCode();
    die("ZCRM Exception Dead");
} catch (Exception $e) {
    echo "<pre>";
    echo $e->getMessage();
    echo "</pre>";
    die("Exception Dead");
}   

** Edit **

$responseIn returns:

object(BulkAPIResponse)#1161 (12) {
  ["bulkData":"BulkAPIResponse":private]=>
  array(0) {
  }
  ["status":"BulkAPIResponse":private]=>
  NULL
  ["info":"BulkAPIResponse":private]=>
  NULL
  ["bulkEntitiesResponse":"BulkAPIResponse":private]=>
  NULL
  ["httpStatusCode":"CommonAPIResponse":private]=>
  int(0)
  ["responseJSON":"CommonAPIResponse":private]=>
  NULL
  ["responseHeaders":"CommonAPIResponse":private]=>
  array(0) {
  }
  ["code":"CommonAPIResponse":private]=>
  NULL
  ["message":"CommonAPIResponse":private]=>
  NULL
  ["details":"CommonAPIResponse":private]=>
  NULL
  ["response":"CommonAPIResponse":private]=>
  bool(false)
  ["apiName":"CommonAPIResponse":private]=>
  NULL
}

Runing the v2 code produces a 'completed' messge so there was not error directly but nothing ends up in the dashboard and more interestingly the API useage reporter shows that nothing is sent (but it does show the authentication requests, so I believe it is connected).

How do I send 'leads' to Zoho via v2 API?

** Edit ** Updated the field names to be the API names.

Upvotes: 0

Views: 147

Answers (1)

Iiskaandar
Iiskaandar

Reputation: 394

In my opinion, your attributes are put incorrectly. Instead of "Last Name" you should put "Last_Name".

Upvotes: 2

Related Questions