How to create a record on Zoho CRM through API (insertRecords method)

734 views Asked by At

I was looking at Zoho CRM API (https://www.zoho.com/crm/help/api/insertrecords.html#Insert_records_into_Zoho_CRM_from_third-party_applications) and there is a method called insertRecords. But I have no idea how should I use to really create a method. Even though there is an example there, I just cant seem to understand it. Should I create a script (with php or python) to handle it? How do I run their example code??

Example of insertRecords usage that they show on their API:

https://crm.zoho.com/crm/private/xml/Leads/insertRecords?
newFormat=1
&authtoken=Auth Token
&scope=crmapi
&xmlData=

<Leads>
<row no="1">
<FL val="Lead Source">Web Download</FL>
<FL val="Company">Your Company</FL>
<FL val="First Name">Hannah</FL>
<FL val="Last Name">Smith</FL>
<FL val="Email">[email protected]</FL>
<FL val="Title">Manager</FL>
<FL val="Phone">1234567890</FL>
<FL val="Home Phone">0987654321</FL>
<FL val="Other Phone">1212211212</FL>
<FL val="Fax">02927272626</FL>
<FL val="Mobile">292827622</FL>
</row>
</Leads>

I do know how to fill this fields like Authtoken and others, but I do not know how can I use this piece of code to generate a new record.

2

There are 2 answers

0
ZohoCoder On

Yes, create a script. PHP and Python are good options. Also Curl is a good option.

The following are good PHP examples to base your implementation on:

Bolii's function public function postData() at:
Using-php-to-insert-records-to-zoho-crm-via-the-api

And

Digant Shah's example at:
https://stackoverflow.com/a/25679415/14250642


Zoho CRM also has a Json alternative that can be used instead of Xml.
Here is the link to the documentation, which provides a good example.
Zoho CRM insertRecords API for Json

0
user4070102 On

Here's an example of how you might use PHP to make the request:

<?php
    $url = "https://crm.zoho.com/crm/private/xml/Leads/insertRecords";
    $xmlData = "<Leads><row no='1'><FL val='Lead Source'>Web Download</FL><FL val='Company'>Your Company</FL><FL val='First Name'>Hannah</FL><FL val='Last Name'>Smith</FL><FL val='Email'>[email protected]</FL><FL val='Title'>Manager</FL><FL val='Phone'>1234567890</FL><FL val='Home Phone'>0987654321</FL><FL val='Other Phone'>1212211212</FL><FL val='Fax'>02927272626</FL><FL val='Mobile'>292827622</FL></row></Leads>";
    $postData = array(
        "newFormat" => 1,
        "authtoken" => "YOUR_AUTH_TOKEN",
        "scope" => "crmapi",
        "xmlData" => $xmlData
    );
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
    $response = curl_exec($ch);
    curl_close($ch);
    print_r($response);
?>

This code uses the cURL library in PHP to make a POST request to the Zoho CRM server, with the necessary parameters and XML data included in the request.

The information is based on the insertRecords method of the Zoho CRM API documentation, accessible at this link.