Once I got the OAuth working for Zoho , I could use the Zoho API version 2.0.

I wanted to add a new Lead to Zoho from my website. I couldn’t find any examples of this, but I finally figured it out. This is the code that worked for me:

function add_lead() {
    records = [];
      $record = ZCRMRecord::getInstance("Leads", null);
      $record->setFieldValue("First_Name", "Cindy");
      $record->setFieldValue("Last_Name", "Cullen");
      $record->setFieldValue("Email", "cindy@example.com");
      $record->setFieldValue("Website", "https://cullenwebservices.com");
      $records[] = $record;

      $zcrmModuleIns = ZCRMModule::getInstance("Leads");
      $response = $zcrmModuleIns->createRecords($records);
      $entityResponses = $response->getEntityResponses();
      foreach ($entityResponses as $entityResponse)	
          if("success"==$entityResponse->getStatus()) {
	    print( "Status:".$entityResponse->getStatus() );
	    print( "Message:".$entityResponse->getMessage() );
	    print( "Code:".$entityResponse->getCode() );
	    print( "EntityID:".$createdRecordInstance->getEntityId() );
	    print( "moduleAPIName:".$createdRecordInstance->getModuleAPIName() );
	} else {
	    print( "Status:".$entityResponse->getStatus() );
	    print( "Message:".$entityResponse->getMessage() );
	    print( "Code:".$entityResponse->getCode() );
    print('response: ');
    print_r($response, true);
  } catch (ZCRMException $e) {
    echo $e->getCode();
    echo $e->getMessage();
    echo $e->getExceptionCode();

Again, this wouldn’t work until I got the OAuth working.

3 thoughts on “Creating Leads with the Zoho 2.0 API”

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top