Get Records API
A record is an entity which stores all the combined information of a particular contact or company, which is acquired from various sources. The information may be acquired from a web-form, social media services, advertisements etc. The records API allows the user to get, create, update, delete, or search records.
Purpose
To get the list of available records from a module.
Request Details
Request URL
https://www.zohoapis.com/crm/v2/{module_api_name}
To get specific record:
https://www.zohoapis.com/crm/v2/{module_api_name}/{record_id}
Supported modules
Leads, Accounts, Contacts, Deals, Campaigns, Tasks, Cases, Events, Calls, Solutions, Products, Vendors, Price Books, Quotes, Sales Orders, Purchase Orders, Invoices, Activities, and custom modules (Refer to the following section).
Custom modules
For custom modules, use their respective API names in the request URL. You can obtain the API name from Setup -> Developer Space -> APIs -> API Names. You can also use the respective custom module's api_name key in the Modules API's response to get the API name of the custom module.
Header
Authorization: Zoho-oauthtoken d92d4xxxxxxxxxxxxx15f52
If-Modified-Since: Use this header to get the list of recently modified records. Example: 2019-07-25T15:26:49+05:30
Scope
scope=ZohoCRM.modules.ALL
(or)
scope=ZohoCRM.modules.{module_name}.{operation_type}
Possible module names
leads, accounts, contacts, deals, campaigns, tasks, cases, events, calls, solutions, products, vendors, pricebooks, quotes, salesorders, purchaseorders, invoices, activities, and custom
Note: The module name for all the custom modules will be custom.
Possible operation types
ALL - Full access to the record
READ - Get records from the module
Parameters
- fieldsstring, optional
To retrieve specific field values.
Possible values: Comma separated field API names. Example: Last_Name,Email - idsstring, optional
To retrieve specific records based on their unique ID.
Possible values: Valid unique IDs of records. Example: 4150868000001944196 - sort_orderstring, optional
To sort the list of records in either ascending or descending order.
Possible values:asc - ascending order; desc - descending order - sort_bystring, optional
Specify the API name of the field based on which the records must be sorted.
Possible values: Field API names. Example: Email - convertedstring, optional
To retrieve the list of converted records. Default value is false.
Possible values:true - get only converted records; false - get only non-converted records; both - get all records - approvedstring, optional
To retrieve the list of approved records. Default value is true.
Possible values:true - get only approved records; false - get only records which are not approved; both - get all records - pageinteger, optional
To get the list of records from the respective pages. Default value for page is 1.
Possible values: Positive Integer values only. - per_pageinteger, optional
To get the list of records available per page. The default and the maximum possible value is 200.
Possible values: Positive Integer values only. - cvidlong, optional
To get the list of records in a custom view.
Possible values: {custom_view_id} which you can get using custom view metadata API. - territory_idstring, optional
To get the list of records in a territory.
Possible values: {territory_id} which you can get using Territory API. - include_childboolean, optional
To include records from the child territories. Default is false.
Possible values:true - include child territory records; false -does not include child territory records
The sort_order parameter applies to given sort_by parameter value.
If sort_by field is not provided, then it applies to the system-defined field.
The page and per_page parameter is used to fetch records according to their position in the CRM. Let's assume that the user has to fetch 400 records. The maximum number of records that one can get for an API call is 200. So, for records above the 200th position, they cannot be fetched. By using the page (1 and 2) and per_page (200) parameter, the user can fetch all 400 records using 2 API calls.
Refer to Response Structure for more details about the JSON keys, values, and their descriptions.
While retrieving multiple records, subform records are not retrieved. Only the records count in a subform is retrieved.
To get the record details in a subform, you need to fetch the specific record information in a module.
To get the list of territories enabled for your organization, refer to Territories API.
Territory is supported only for the modules Deals, Contacts, and Accounts.
Only admin users can fetch the records from the Notes module. The system throws an error when non-admin users try to fetch the records from the Notes module.
To know more about the field types and limits, refer to Insert Records API.
Response JSON Keys
- OwnerJSON object
Represents the name, ID, and email ID of the record owner.
- $currency_symbolstring
Represents the symbol of the currency of the organization. For instance, '₹'.
- $process_flowboolean
Represents if the record is a part of review process.
true: The current record is a part of the review process.
false: The current record is not a part of the review process. This is the default value. - Exchange_Ratedouble
Represents the exchange rate set for the organization.
- Currencystring
Represents the currency of the organization.
- $approvedboolean
Represents if the current record is approved.
true: The current record is approved. This is the default value.
false: The current record is yet to be approved. - $approvalJSON object
Represents the details of the approval process.
- Created_Timestring
Represents the date and time at which the record was created.
- Modified_Timestring
Represents the date and time at which the record was last modified.
- $editableboolean
Represents if the user can edit records in the current module.
true: The user can edit records in the current module. This is the default value.
false: The user does not have permission to edit records in the current module. - Created_ByJSON object
Represents the name, ID, and email of the user who created the current record.
- Modified_ByJSON object
Represents the name, ID, and email of the user who last modified the record.
- $orchestrationboolean
Represents if the current record is a part of orchestration.
The keys listed above are common for all the modules. Along with the above keys, module-specific keys will also be retrieved in the response.
The value of the fields with sensitive health data will be retrieved only when Restrict Data access through API option in the compliance settings is disabled. If the option is enabled, the value will be null. Refer to HIPAA compliance for more details.
Sample Request
Copiedcurl "https://www.zohoapis.com/crm/v2/Leads/1306462000000888026"
-X GET
-H "Authorization: Zoho-oauthtoken 1000.8cb99dxxxxxxxxxxxxx9be93.9b8xxxxxxxxxxxxxxxf"
CopiedString moduleAPIName = "Leads";
//Get instance of RecordOperations Class
RecordOperations recordOperations = new RecordOperations();
ParameterMap paramInstance = new ParameterMap();
paramInstance.add(GetRecordsParam.APPROVED, "both");
//
// paramInstance.add(GetRecordsParam.CONVERTED, "both");
// paramInstance.add(GetRecordsParam.CVID, "3477061000000087501");
// List<long> ids = new ArrayList<long>(Arrays.asList(3477061000005623115, 3477061000004352001));
//
// for(long id : ids)
// {
// paramInstance.add(GetRecordsParam.IDS, id);
// }
//
// paramInstance.add(GetRecordsParam.UID, "3477061000005181008");
//
// List<String> fieldNames = new ArrayList<String>(Arrays.asList("Company", "Email"));
//
// for(String fieldName : fieldNames)
// {
// paramInstance.add(GetRecordsParam.FIELDS, fieldName);
// }
//
// paramInstance.add(GetRecordsParam.SORT_BY, "Email");
//
// paramInstance.add(GetRecordsParam.SORT_ORDER, "desc");
//
// paramInstance.add(GetRecordsParam.PAGE, 1);
//
// paramInstance.add(GetRecordsParam.PER_PAGE, 1);
// OffsetDateTime startdatetime = OffsetDateTime.of(2019, 11, 20, 10, 00, 01, 00, ZoneOffset.of("+05:30"));
//
// paramInstance.add(GetRecordsParam.STARTDATETIME, startdatetime);
//
// OffsetDateTime enddatetime = OffsetDateTime.of(2019, 12, 20, 10, 00, 01, 00, ZoneOffset.of("+05:30"));
//
// paramInstance.add(GetRecordsParam.ENDDATETIME, enddatetime);
//
// paramInstance.add(GetRecordsParam.TERRITORY_ID, "3477061000003051357");
//
// paramInstance.add(GetRecordsParam.INCLUDE_CHILD, true);
HeaderMap headerInstance = new HeaderMap();
OffsetDateTime ifmodifiedsince = OffsetDateTime.of(2019, 05, 20, 10, 00, 01, 00, ZoneOffset.of("+05:30"));
headerInstance.add(GetRecordsHeader.IF_MODIFIED_SINCE, ifmodifiedsince);
//Call getRecords method that takes moduleAPIName, paramInstance and headerInstance as parameter.
APIResponse < ResponseHandler > response = recordOperations.getRecords(moduleAPIName, paramInstance, headerInstance);
Copiedpackage com.zoho.crm.api.sample.restapi.records;
import javax.net.ssl.SSLContext;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
public class GetRecordsAPI
{
private static void getRecords()
{
try
{
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
SSLContext sslContext = SSLContext.getDefault();
SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE);
CloseableHttpClient httpclient = httpClientBuilder.setSSLSocketFactory(sslConnectionSocketFactory).build();
URIBuilder uriBuilder = new URIBuilder("https://www.zohoapis.com/crm/v2/Leads");
uriBuilder.addParameter("approved", "both");
uriBuilder.addParameter("converted", "both");
uriBuilder.addParameter("cvid", "41508681944196");
uriBuilder.addParameter("ids", "34770617738002,34770617736020");
uriBuilder.addParameter("uid", "");
uriBuilder.addParameter("fields", "Last_Name,Email");
uriBuilder.addParameter("sort_by", "Email");
uriBuilder.addParameter("sort_order", "desc");
uriBuilder.addParameter("page", "1");
uriBuilder.addParameter("per_page", "4");
uriBuilder.addParameter("startDateTime", "2021-05-15T12:00:00+05:30");
uriBuilder.addParameter("endDateTime", "2021-06-15T12:00:00+05:30");
uriBuilder.addParameter("territory_id", "");
uriBuilder.addParameter("include_child", "false");
HttpUriRequest requestObj = new HttpGet(uriBuilder.build());
requestObj.addHeader("Authorization", "Zoho-oauthtoken 1000.xxxxxxx.xxxxxxx");
requestObj.addHeader("If-Modified-Since", "2020-10-12T17:59:50+05:30");
HttpResponse response = httpclient.execute(requestObj);
HttpEntity responseEntity = response.getEntity();
System.out.println("HTTP Status Code : " + response.getStatusLine().getStatusCode());
if(responseEntity != null)
{
Object responseObject = EntityUtils.toString(responseEntity);
String responseString = responseObject.toString();
System.out.println(responseString);
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
private static void getRecord()
{
try
{
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
SSLContext sslContext = SSLContext.getDefault();
SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE);
CloseableHttpClient httpclient = httpClientBuilder.setSSLSocketFactory(sslConnectionSocketFactory).build();
URIBuilder uriBuilder = new URIBuilder("https://www.zohoapis.com/crm/v2/Leads/34770615844005");
uriBuilder.addParameter("approved", "both");
uriBuilder.addParameter("converted", "both");
uriBuilder.addParameter("cvid", "41508681944196");
uriBuilder.addParameter("uid", "");
uriBuilder.addParameter("fields", "Last_Name,Email");
uriBuilder.addParameter("startDateTime", "2021-05-15T12:00:00+05:30");
uriBuilder.addParameter("endDateTime", "2021-06-15T12:00:00+05:30");
uriBuilder.addParameter("territory_id", "");
uriBuilder.addParameter("include_child", "false");
HttpUriRequest requestObj = new HttpGet(uriBuilder.build());
requestObj.addHeader("Authorization", "Zoho-oauthtoken 1000.xxxxxxx.xxxxxxx");
requestObj.addHeader("If-Modified-Since", "2020-10-12T17:59:50+05:30");
HttpResponse response = httpclient.execute(requestObj);
HttpEntity responseEntity = response.getEntity();
System.out.println("HTTP Status Code : " + response.getStatusLine().getStatusCode());
if(responseEntity != null)
{
Object responseObject = EntityUtils.toString(responseEntity);
String responseString = responseObject.toString();
System.out.println(responseString);
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
public static void main(String[] args)
{
getRecords();
getRecord();
}
}
Copied//Get instance of RecordOperations Class that takes moduleAPIName as parameter
$recordOperations = new RecordOperations();
$paramInstance = new ParameterMap();
$paramInstance->add(GetRecordsParam::fields(), "id");
$paramInstance->add(GetRecordsParam::page(), 1);
$paramInstance->add(GetRecordsParam::perPage(), 3);
$startdatetime = date_create("2020-06-27T15:10:00+05:30")->setTimezone(new \DateTimeZone(date_default_timezone_get()));
$headerInstance = new HeaderMap();
$response = $recordOperations->getRecords($moduleAPIName,$paramInstance, $headerInstance);
Copied<?php
class GetRecords{
public function execute(){
$curl_pointer = curl_init();
$curl_options = array();
$url = "https://www.zohoapis.com/crm/v2/Leads?";
$parameters = array();
$parameters["page"]="1";
$parameters["per_page"]="2";
$parameters["sort_by"]="Email2";
$parameters["sort_order"]="desc2";
$parameters["include_child"]="false";
foreach ($parameters as $key=>$value){
$url =$url.$key."=".$value."&";
}
$curl_options[CURLOPT_URL] = $url;
$curl_options[CURLOPT_RETURNTRANSFER] = true;
$curl_options[CURLOPT_HEADER] = 1;
$curl_options[CURLOPT_CUSTOMREQUEST] = "GET";
$headersArray = array();
$headersArray[] = "Authorization". ":" . "Zoho-oauthtoken " ."1000.8cb99dxxxxxxxxxxxxx9be93.9b8xxxxxxxxxxxxxxxf";
$headersArray[] = "If-Modified-Since".":"."2021-10-12T17:59:50+05:30";
$curl_options[CURLOPT_HTTPHEADER]=$headersArray;
curl_setopt_array($curl_pointer, $curl_options);
$result = curl_exec($curl_pointer);
$responseInfo = curl_getinfo($curl_pointer);
curl_close($curl_pointer);
list ($headers, $content) = explode("\r\n\r\n", $result, 2);
if(strpos($headers," 100 Continue")!==false){
list( $headers, $content) = explode( "\r\n\r\n", $content , 2);
}
$headerArray = (explode("\r\n", $headers, 50));
$headerMap = array();
foreach ($headerArray as $key) {
if (strpos($key, ":") != false) {
$firstHalf = substr($key, 0, strpos($key, ":"));
$secondHalf = substr($key, strpos($key, ":") + 1);
$headerMap[$firstHalf] = trim($secondHalf);
}
}
$jsonResponse = json_decode($content, true);
if ($jsonResponse == null && $responseInfo['http_code'] != 204) {
list ($headers, $content) = explode("\r\n\r\n", $content, 2);
$jsonResponse = json_decode($content, true);
}
var_dump($headerMap);
var_dump($jsonResponse);
var_dump($responseInfo['http_code']);
}
}
(new GetRecords())->execute();
Copied//Get instance of RecordOperations Class
RecordOperations recordOperations = new RecordOperations();
//Get instance of ParameterMap Class
ParameterMap paramInstance = new ParameterMap();
//paramInstance.Add(GetRecordParam.APPROVED, "false");
//paramInstance.Add(GetRecordParam.CONVERTED, "false");
List<string> fieldNames = new List<string>() { "Company", "Email" };
foreach (string fieldName in fieldNames)
{
paramInstance.Add(GetRecordParam.FIELDS, fieldName);
}
DateTimeOffset startdatetime = new DateTimeOffset(new DateTime(2020, 10, 15, 12, 0, 1, DateTimeKind.Local));
paramInstance.Add(GetRecordParam.STARTDATETIME, startdatetime);
DateTimeOffset enddatetime = new DateTimeOffset(new DateTime(2020, 11, 15, 12, 0, 1, DateTimeKind.Local));
paramInstance.Add(GetRecordParam.ENDDATETIME, enddatetime);
//paramInstance.Add(GetRecordParam.TERRITORY_ID, "3477061000003051357");
paramInstance.Add(GetRecordParam.INCLUDE_CHILD, "true");
HeaderMap headerInstance = new HeaderMap();
//DateTimeOffset ifmodifiedsince = new DateTimeOffset(new DateTime(2020, 05, 15, 12, 0, 0, DateTimeKind.Local));
//headerInstance.Add(GetRecordHeader.IF_MODIFIED_SINCE, ifmodifiedsince);
//Call getRecord method that takes recordID, moduleAPIName, paramInstance, and headerInstance as parameter
APIResponse<ResponseHandler> response = recordOperations.GetRecord(recordId, moduleAPIName, paramInstance, headerInstance);
Copiedusing System;
using System.IO;
using System.Net;
using System.Xml;
using Newtonsoft.Json;
namespace Com.Zoho.Crm.API.Sample.RestAPI.Records
{
public class GetRecordsAPI
{
public static void GetRecords()
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.zohoapis.com/crm/v2/Leads?approved=both");
request.Method = "GET";
request.Headers["Authorization"] = "Zoho-oauthtoken 1000.74553e99426b9XXXXX1asvdse.9907113ad479cdfaXXXXXXXXXe9d1f68f135";
string IfModifiedSince = JsonConvert.SerializeObject("2020-05-15T12:00:00+05:30");
IfModifiedSince = IfModifiedSince.Replace("\\", "");
IfModifiedSince = IfModifiedSince.Replace("\"", "");
DateTime dateConversion = XmlConvert.ToDateTime(IfModifiedSince, XmlDateTimeSerializationMode.Utc);
request.IfModifiedSince = dateConversion;
request.KeepAlive = true;
HttpWebResponse response;
try
{
response = (HttpWebResponse)request.GetResponse();
}
catch (WebException e)
{
if (e.Response == null) { throw; }
response = (HttpWebResponse)e.Response;
}
HttpWebResponse responseEntity = response;
Console.WriteLine("HTTP Status Code : " + (int)response.StatusCode);
string responsestring = new StreamReader(responseEntity.GetResponseStream()).ReadToEnd();
responseEntity.Close();
Console.WriteLine(responsestring);
}
public static void GetRecord()
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.zohoapis.com/crm/v2/Leads/34770615844005?approved=both");
request.Method = "GET";
request.Headers["Authorization"] = "Zoho-oauthtoken 1000.745XXXXXXXXXXXXXXXXXXXXXXf0d9572c.9907XXXXXXXXXXXXXXXXXf135";
string IfModifiedSince = JsonConvert.SerializeObject("2020-05-15T12:00:00+05:30");
IfModifiedSince = IfModifiedSince.Replace("\\", "");
IfModifiedSince = IfModifiedSince.Replace("\"", "");
DateTime dateConversion = XmlConvert.ToDateTime(IfModifiedSince, XmlDateTimeSerializationMode.Utc);
request.IfModifiedSince = dateConversion;
request.KeepAlive = true;
HttpWebResponse response;
try
{
response = (HttpWebResponse)request.GetResponse();
}
catch (WebException e)
{
if (e.Response == null) { throw; }
response = (HttpWebResponse)e.Response;
}
HttpWebResponse responseEntity = response;
Console.WriteLine("HTTP Status Code : " + (int)response.StatusCode);
string responsestring = new StreamReader(responseEntity.GetResponseStream()).ReadToEnd();
responseEntity.Close();
Console.WriteLine(responsestring);
}
}
}
Copied# Get instance of RecordOperations Class
record_operations = RecordOperations()
# Get instance of ParameterMap Class
param_instance = ParameterMap()
ids = ["LeadsExternal", "3477061000004352001"]
# Possible parameters for Get Records operation
param_instance.add(GetRecordsParam.page, 1)
param_instance.add(GetRecordsParam.per_page, 120)
param_instance.add(GetRecordsParam.approved, 'both')
param_instance.add(GetRecordsParam.converted, 'both')
param_instance.add(GetRecordsParam.cvid, '3409643000000087501')
for each_id in ids:
param_instance.add(GetRecordsParam.ids, each_id)
param_instance.add(GetRecordsParam.uid, '3409643000000302031')
field_names = ["Company", "Email"]
for field in field_names:
param_instance.add(GetRecordsParam.fields, field)
param_instance.add(GetRecordsParam.sort_by, 'Email')
param_instance.add(GetRecordsParam.sort_order, 'desc')
start_date_time = datetime(2020, 1, 1, 0, 0, 0)
param_instance.add(GetRecordsParam.startdatetime, start_date_time)
end_date_time = datetime(2020, 7, 1, 0, 0, 0)
param_instance.add(GetRecordsParam.enddatetime, end_date_time)
param_instance.add(GetRecordsParam.territory_id, '3409643000000505351')
param_instance.add(GetRecordsParam.include_child, "true")
# Get instance of HeaderMap Class
header_instance = HeaderMap()
# Possible headers for Get Records operation
header_instance.add(GetRecordsHeader.if_modified_since, datetime.fromisoformat('2020-01-01T00:00:00+05:30'))
# header_instance.add(GetRecordsHeader.x_external, "Leads.External")
# Call get_records method that takes ParameterMap Instance, HeaderMap Instance and module_api_name as parameters
response = record_operations.get_records(module_api_name, param_instance, header_instance)
# Get instance of RecordOperations Class
record_operations = RecordOperations()
# Get instance of ParameterMap Class
param_instance = ParameterMap()
# Possible parameters for Get Record operation
param_instance.add(GetRecordParam.cvid, '3409643000000087501')
param_instance.add(GetRecordParam.approved, 'true')
param_instance.add(GetRecordParam.converted, 'both')
fields = ['id', 'company']
for field in fields:
param_instance.add(GetRecordParam.fields, field)
start_date_time = datetime(2020, 1, 1, 10, 10, 10)
param_instance.add(GetRecordParam.startdatetime, start_date_time)
end_date_time = datetime(2020, 7, 7, 10, 10, 10)
param_instance.add(GetRecordParam.enddatetime, end_date_time)
param_instance.add(GetRecordParam.territory_id, '3409643000000505351')
param_instance.add(GetRecordParam.include_child, 'true')
param_instance.add(GetRecordParam.uid, '3409643000000500741')
# Get instance of HeaderMap Class
header_instance = HeaderMap()
# Possible headers for Get Record operation
header_instance.add(GetRecordHeader.if_modified_since, datetime.now())
# header_instance.add(GetRecordHeader.x_external, "Leads.External")
# Call getRecord method that takes param_instance, header_instance, module_api_name and record_id as parameter
response = record_operations.get_record(record_id, module_api_name, param_instance, header_instance)
Copieddef get_records():
import requests
url = 'https://www.zohoapis.com/crm/v2/Leads'
headers = {
'Authorization': 'Zoho-oauthtoken 1000.04be928e4a96XXXXXXXXXXXXX68.0b9eXXXXXXXXXXXX60396e268',
'If-Modified-Since': '2020-03-19T17:59:50+05:30'
}
parameters = {
'approved': 'both',
'converted': 'both',
'cvid': '3409643000002804006',
'ids': '3409643000002804010,3409643000002804109',
'uid': '3409643000002804154',
'fields': 'Last_Name,Email',
'sort_by': 'Email',
'sort_order': 'desc',
'page': '1',
'per_page': '100',
'startDateTime': '2020-05-15T12:00:00+05:30',
'endDateTime': '2020-10-15T12:00:00+05:30',
'territory_id': '3409643000002804205',
'include_child': 'false',
}
response = requests.get(url=url, headers=headers, params=parameters)
if response is not None:
print("HTTP Status Code : " + str(response.status_code))
print(response.json())
get_records()
def get_record():
import requests
url = 'https://www.zohoapis.com/crm/v2/Leads/3409643000002804010'
headers = {
'Authorization': 'Zoho-oauthtoken 1000.04be928e4a96XXXXXXXXXXXXX68.0b9eXXXXXXXXXXXX60396e268',
'If-Modified-Since': '2020-03-19T17:59:50+05:30'
}
parameters = {
'approved': 'both',
'converted': 'both',
'cvid': '3409643000002804006',
'uid': '3409643000002804154',
'fields': 'Last_Name,Email',
'startDateTime': '2020-05-15T12:00:00+05:30',
'endDateTime': '2020-10-15T12:00:00+05:30',
'territory_id': '3409643000002804205',
'include_child': 'false',
}
response = requests.get(url=url, headers=headers, params=parameters)
if response is not None:
print("HTTP Status Code : " + str(response.status_code))
print(response.json())
get_record()
Copied//Get instance of RecordOperations Class
let recordOperations = new RecordOperations();
//Get instance of ParameterMap Class
let paramInstance = new ParameterMap();
/* Possible parameters for Get Records operation*/
await paramInstance.add(GetRecordsParam.APPROVED, "both");
await paramInstance.add(GetRecordsParam.CONVERTED, "both");
await paramInstance.add(GetRecordsParam.CVID, "3477061000000087501");
let ids = [3477061000005623115n, 3477061000004352001n];
for(let id of ids) {
await paramInstance.add(GetRecordsParam.IDS, id);
}
await paramInstance.add(GetRecordsParam.UID, "3477061000005181008");
let fieldNames = ["Company", "Email"];
await paramInstance.add(GetRecordsParam.FIELDS, fieldNames.toString());
await paramInstance.add(GetRecordsParam.SORT_BY, "Email");
await paramInstance.add(GetRecordsParam.SORT_ORDER, "desc");
await paramInstance.add(GetRecordsParam.PAGE, 1);
await paramInstance.add(GetRecordsParam.PER_PAGE, 200);
let startDateTime = new Date(2020,1,10,10,10,10);
await paramInstance.add(GetRecordsParam.STARTDATETIME, startDateTime);
let endDateTime = new Date(2020,7,10,12,12,12);
await paramInstance.add(GetRecordsParam.ENDDATETIME, endDateTime);
await paramInstance.add(GetRecordsParam.TERRITORY_ID, "3409643000000505351");
await paramInstance.add(GetRecordsParam.INCLUDE_CHILD, "true");
//Get instance of HeaderMap Class
let headerInstance = new HeaderMap();
/* Possible headers for Get Record operation*/
await headerInstance.add(GetRecordsHeader.IF_MODIFIED_SINCE, new Date("2020-01-01T00:00:00+05:30"));
//Call getRecords method that takes paramInstance, headerInstance and moduleAPIName as parameters
let response = await recordOperations.getRecords(moduleAPIName, paramInstance, headerInstance);
Copiedasync function getRecords() {
const got = require("got");
let url = 'https://www.zohoapis.com/crm/v2/Leads'
let headers = {
Authorization : "Zoho-oauthtoken 1000.8cb99dxxxxxxxxxxxxx9be93.9b8xxxxxxxxxxxxxxxf",
'If-Modified-Since': '2020-03-19T17:59:50+05:30'
}
let parameters = {
'approved': 'both',
'converted': 'both',
'cvid': '3409643000002804006',
'ids': '3409643000002804010,3409643000002804109',
'uid': '3409643000002804154',
'fields': 'Last_Name,Email',
'sort_by': 'Email',
'sort_order': 'desc',
'page': '1',
'per_page': '100',
'startDateTime': '2020-05-15T12:00:00+05:30',
'endDateTime': '2020-10-15T12:00:00+05:30',
'territory_id': '3409643000002804205',
'include_child': 'false'
}
let requestDetails = {
method : "GET",
headers : headers,
searchParams : parameters,
throwHttpErrors : false
}
let response = await got(url, requestDetails)
if(response != null) {
console.log(response.statusCode);
console.log(response.body);
}
}
getRecords()
async function getRecord() {
const got = require("got");
let url = 'https://www.zohoapis.com/crm/v2/Leads/3409643000002804010'
let headers = {
Authorization : "Zoho-oauthtoken 1000.8cb99dxxxxxxxxxxxxx9be93.9b8xxxxxxxxxxxxxxxf",
'If-Modified-Since': '2020-03-19T17:59:50+05:30'
}
let parameters = {
'approved': 'both',
'converted': 'both',
'cvid': '3409643000002804006',
'uid': '3409643000002804154',
'fields': 'Last_Name,Email',
'startDateTime': '2020-05-15T12:00:00+05:30',
'endDateTime': '2020-10-15T12:00:00+05:30',
'territory_id': '3409643000002804205',
'include_child': 'false',
}
let requestDetails = {
method : "GET",
headers : headers,
searchParams : parameters,
throwHttpErrors : false
}
let response = await got(url, requestDetails)
if(response != null) {
console.log(response.statusCode);
console.log(response.body);
}
}
getRecord()
Copied# Get instance of RecordOperations Class
ro = Record::RecordOperations.new
# Get instance of ParameterMap Class
pm = ParameterMap.new
# module_api_name = "Leads"
# record_id = 3524033000005662018
# pm.add(Record::RecordOperations::GetRecordParam.approved,"false")
# pm.add(Record::RecordOperations::GetRecordParam.converted,"false")
# field_names =["Company","Email"]
# field_names.each do |field_name|
# pm.add(Record::::RecordOperations::GetRecordParam.fields,field_name)
# end
# Get instance of HeaderMap Class
hm = HeaderMap.new
# hm.add(Record::RecordOperations::GetRecordHeader.If_modified_since,"")
# Call getRecord method that takes param_instance, header_instance, module_api_name and record_id as parameter
response = ro.get_record(record_id,module_api_name,pm, hm)
# Get instance of RecordOperations Class
ro = Record::RecordOperations.new
# Get instance of ParameterMap Class
pm = ParameterMap.new
# record_id = 3524033000005495066
# Add the per_page to ParameterMap instance
pm.add(Record::RecordOperations::GetRecordsParam.per_page, 1)
pm.add(Record::RecordOperations::GetRecordsParam.converted, 'false')
# field_names =["Company","Email"]
# field_names.each do |field_name|
# pm.add(Record::::RecordOperations::GetRecordParam.fields,field_name)
# end
# Get instance of HeaderMap Class
hm = HeaderMap.new
# hm.add(Record::RecordOperations::GetRecordHeader.If_modified_since,"")
# Call getRecords method that takes ParameterMap Instance, HeaderMap Instance and module_api_name as parameters
response = ro.get_records(module_api_name,pm, hm)
Copiedclass GetRecords
def execute
parameters ={}
parameters["per_page"]="2";
parameters["page"]="1";
parameters["sort_by"]="Email2";
parameters["sort_order"]="desc2";
parameters["include_child"]="false";
query_string = parameters.to_a.map { |x| "#{x[0]}=#{x[1]}" }.join('&')
url= "https://www.zohoapis.com/crm/v2/Leads"
url += '?' + query_string if !query_string.nil? && (query_string.strip != '')
url = URI(url)
req = Net::HTTP::Get.new(url.request_uri)
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
headers={}
headers["Authorization"]="Zoho-oauthtoken 1000.50XXXXXXXXX&77e3a.44XXXXXXXXX8353"
headers["If-Modified-Since"]="2019-10-12T17:59:50+05:30"
headers&.each { |key, value| req.add_field(key, value) }
response=http.request(req)
status_code = response.code.to_i
headers = response.each_header.to_h
print status_code
print headers
unless response.body.nil?
print response.body
end
end
end
GetRecords.new.execute
Copied//Get instance of RecordOperations Class
let recordOperations = new ZCRM.Record.Operations();
//Get instance of ParameterMap Class
let paramInstance = new ParameterMap();
/* Possible parameters for Get Records operation*/
await paramInstance.add(ZCRM.Record.Model.GetRecordsParam.APPROVED, "both");
await paramInstance.add(ZCRM.Record.Model.GetRecordsParam.CONVERTED, "both");
await paramInstance.add(ZCRM.Record.Model.GetRecordsParam.CVID, "347706187501");
let ids = [34770615623115n, 34770614352001n];
for(let id of ids) {
await paramInstance.add(ZCRM.Record.Model.GetRecordsParam.IDS, id);
}
await paramInstance.add(ZCRM.Record.Model.GetRecordsParam.UID, "34770615181008");
let fieldNames = ["Company", "Email"];
await paramInstance.add(ZCRM.Record.Model.GetRecordsParam.FIELDS, fieldNames.toString());
await paramInstance.add(ZCRM.Record.Model.GetRecordsParam.SORT_BY, "Email");
await paramInstance.add(ZCRM.Record.Model.GetRecordsParam.SORT_ORDER, "desc");
await paramInstance.add(ZCRM.Record.Model.GetRecordsParam.PAGE, 1);
await paramInstance.add(ZCRM.Record.Model.GetRecordsParam.PER_PAGE, 200);
let startDateTime = new Date(2020,1,10,10,10,10);
await paramInstance.add(ZCRM.Record.Model.GetRecordsParam.STARTDATETIME, startDateTime);
let endDateTime = new Date(2020,7,10,12,12,12);
await paramInstance.add(ZCRM.Record.Model.GetRecordsParam.ENDDATETIME, endDateTime);
await paramInstance.add(ZCRM.Record.Model.GetRecordsParam.TERRITORY_ID, "3409643505351");
await paramInstance.add(ZCRM.Record.Model.GetRecordsParam.INCLUDE_CHILD, "true");
//Get instance of HeaderMap Class
let headerInstance = new HeaderMap();
/* Possible headers for Get Record operation*/
await headerInstance.add(ZCRM.Record.Model.GetRecordsHeader.IF_MODIFIED_SINCE, new Date("2020-01-01T00:00:00+05:30"));
//Call getRecords method that takes paramInstance, headerInstance and moduleAPIName as parameters
let response = await recordOperations.getRecords(moduleAPIName);
Copiedvar listener = 0;
class GetRecordsAPI {
async getRecords() {
var url = "https://www.zohoapis.com/crm/v2/Leads"
var parameters = new Map()
var headers = new Map()
var token = {
clientId:"1000.NPY9M1V0XXXXXXXXXXXXXXXXXXXF7H",
redirectUrl:"http://127.0.0.1:5500/redirect.html",
scope:"ZohoCRM.users.ALL,ZohoCRM.bulk.read,ZohoCRM.modules.ALL,ZohoCRM.settings.ALL,Aaaserver.profile.Read,ZohoCRM.org.ALL,profile.userphoto.READ,ZohoFiles.files.ALL,ZohoCRM.bulk.ALL,ZohoCRM.settings.variable_groups.ALL"
}
var accesstoken = await new GetRecordsAPI().getToken(token)
headers.set("Authorization", "Zoho-oauthtoken " + accesstoken)
headers.set("If-Modified-Since", "2020-10-12T17:59:50+05:30")
parameters.set("approved", "both")
parameters.set("converted", "both")
parameters.set("cvid", "41508681944196")
parameters.set("ids", "34770617738002,34770617736020")
parameters.set("uid", "")
parameters.set("fields", "Last_Name,Email")
parameters.set("sort_by", "Email")
parameters.set("sort_order", "desc")
parameters.set("page", "1")
parameters.set("per_page", "4")
parameters.set("startDateTime", "2021-05-15T12:00:00+05:30")
parameters.set("endDateTime", "2021-06-15T12:00:00+05:30")
parameters.set("territory_id", "")
parameters.set("include_child", "false")
var requestMethod = "GET"
var reqBody = null
var params = "";
parameters.forEach(function(value, key) {
if (parameters.has(key)) {
if (params) {
params = params + key + '=' + value + '&';
}
else {
params = key + '=' + value + '&';
}
}
});
var apiHeaders = {};
if(headers) {
headers.forEach(function(value, key) {
apiHeaders[key] = value;
});
}
if (params.length > 0){
url = url + '?' + params.substring(0, params.length - 1);
}
var requestObj = {
uri : url,
method : requestMethod,
headers : apiHeaders,
body : JSON.stringify(reqBody),
encoding: "utf8",
allowGetBody : true,
throwHttpErrors : false
};
var result = await new GetRecordsAPI().makeAPICall(requestObj);
console.log(result.status)
console.log(result.response)
}
async getRecord() {
var url = "https://www.zohoapis.com/crm/v2/Leads/34770619080127"
var parameters = new Map()
var headers = new Map()
var token = {
clientId:"1000.NPY9M1V0XXXXXXXXXXXXXXXXXXXF7H",
redirectUrl:"http://127.0.0.1:5500/redirect.html",
scope:"ZohoCRM.users.ALL,ZohoCRM.bulk.read,ZohoCRM.modules.ALL,ZohoCRM.settings.ALL,Aaaserver.profile.Read,ZohoCRM.org.ALL,profile.userphoto.READ,ZohoFiles.files.ALL,ZohoCRM.bulk.ALL,ZohoCRM.settings.variable_groups.ALL"
}
var accesstoken = await new GetRecordsAPI().getToken(token)
headers.set("Authorization", "Zoho-oauthtoken " + accesstoken)
headers.set("If-Modified-Since", "2020-10-12T17:59:50+05:30")
parameters.set("approved", "both")
parameters.set("converted", "both")
parameters.set("cvid", "41508681944196")
parameters.set("uid", "")
parameters.set("fields", "Last_Name,Email")
parameters.set("startDateTime", "2021-05-15T12:00:00+05:30")
parameters.set("endDateTime", "2021-06-15T12:00:00+05:30")
parameters.set("territory_id", "")
parameters.set("include_child", "false")
var requestMethod = "GET"
var reqBody = null
var params = "";
parameters.forEach(function(value, key) {
if (parameters.has(key)) {
if (params) {
params = params + key + '=' + value + '&';
}
else {
params = key + '=' + value + '&';
}
}
});
var apiHeaders = {};
if(headers) {
headers.forEach(function(value, key) {
apiHeaders[key] = value;
});
}
if (params.length > 0){
url = url + '?' + params.substring(0, params.length - 1);
}
var requestObj = {
uri : url,
method : requestMethod,
headers : apiHeaders,
body : JSON.stringify(reqBody),
encoding: "utf8",
allowGetBody : true,
throwHttpErrors : false
};
var result = await new GetRecordsAPI().makeAPICall(requestObj);
console.log(result.status)
console.log(result.response)
}
async getToken(token) {
if(listener == 0) {
window.addEventListener("storage", function(reponse) {
if(reponse.key === "access_token" && (reponse.oldValue != reponse.newValue || reponse.oldValue == null)){
location.reload();
}
if(reponse.key === "access_token"){
sessionStorage.removeItem("__auth_process");
}
}, false);
listener = 1;
if(sessionStorage.getItem("__auth_process")) {
sessionStorage.removeItem("__auth_process");
}
}
["granted_for_session", "access_token","expires_in","expires_in_sec","location","api_domain","state","__token_init","__auth_process"].forEach(function (k) {
var isKeyExists = localStorage.hasOwnProperty(k);
if(isKeyExists) {
sessionStorage.setItem(k, localStorage[k]);
}
localStorage.removeItem(k);
});
var valueInStore = sessionStorage.getItem("access_token");
var tokenInit = sessionStorage.getItem("__token_init");
if(tokenInit != null && valueInStore != null && Date.now() >= parseInt(tokenInit) + 59 * 60 * 1000){ // check after 59th minute
valueInStore = null;
sessionStorage.removeItem("access_token");
}
var auth_process = sessionStorage.getItem("__auth_process");
if ((valueInStore == null && auth_process == null) || (valueInStore == 'undefined' && (auth_process == null || auth_process == "true"))) {
var accountsUrl = "https://accounts.zoho.com/oauth/v2/auth"
var clientId;
var scope;
var redirectUrl;
if(token != null) {
clientId = token.clientId;
scope = token.scope;
redirectUrl = token.redirectUrl;
}
var fullGrant = sessionStorage.getItem("full_grant");
var grantedForSession = sessionStorage.getItem("granted_for_session");
if(sessionStorage.getItem("__token_init") != null && ((fullGrant != null && "true" == full_grant) || (grantedForSession != null && "true" == grantedForSession))) {
accountsUrl += '/refresh';
}
if (clientId && scope) {
sessionStorage.setItem("__token_init", Date.now());
sessionStorage.removeItem("access_token");
sessionStorage.setItem("__auth_process", "true");
window.open(accountsUrl + "?" + "scope" + "=" + scope + "&"+ "client_id" +"=" + clientId + "&response_type=token&state=zohocrmclient&redirect_uri=" + redirectUrl);
["granted_for_session", "access_token","expires_in","expires_in_sec","location","api_domain","state","__token_init","__auth_process"].forEach(function (k) {
var isKeyExists = localStorage.hasOwnProperty(k);
if(isKeyExists){
sessionStorage.setItem(k, localStorage[k]);
}
localStorage.removeItem(k);
});
valueInStore = sessionStorage.getItem("access_token");
}
}
if(token != null && valueInStore != 'undefined'){
token.accessToken = valueInStore;
}
return token.accessToken;
}
async makeAPICall(requestDetails) {
return new Promise(function (resolve, reject) {
var body, xhr, i;
body = requestDetails.body || null;
xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.open(requestDetails.method, requestDetails.uri, true);
for (i in requestDetails.headers) {
xhr.setRequestHeader(i, requestDetails.headers[i]);
}
xhr.send(body);
xhr.onreadystatechange = function() {
if(xhr.readyState == 4) {
resolve(xhr);
}
}
})
}
}
Copiedresponse = invokeurl
[
url: "https://www.zohoapis.com/crm/v2/Accounts"
type: GET
connection:"crm_oauth_connection"
];
info response;
Sample Response
Copied{
"data": [
{
"Owner": {
"name": "Patricia Boyle",
"id": "1306462000000374001",
"email": "p.boyle@abc.com"
},
"Company": "SolutionsTech",
"Email": null,
"$currency_symbol": "$",
"$field_states": null,
"Last_Activity_Time": "2022-02-03T10:55:15+05:30",
"Industry": null,
"$state": "save",
"Unsubscribed_Mode": null,
"$converted": false,
"$process_flow": false,
"Test": null,
"Street": null,
"Data_Processing_Basis_Details": null,
"Zip_Code": null,
"id": "1306462000000888026",
"Data_Source": "API",
"$approved": true,
"$approval": {
"delegate": false,
"approve": false,
"reject": false,
"resubmit": false
},
"$data_source_details": {},
"Created_Time": "2022-02-02T17:09:49+05:30",
"$editable": true,
"City": null,
"No_of_Employees": null,
"Related": null,
"State": null,
"Country": null,
"Created_By": {
"name": "Patricia Boyle",
"id": "1306462000000374001",
"email": "p.boyle@abc.com"
},
"Annual_Revenue": null,
"Secondary_Email": null,
"Description": null,
"Rating": null,
"$review_process": {
"approve": false,
"reject": false,
"resubmit": false
},
"Website": null,
"Twitter": null,
"Information": null,
"$canvas_id": null,
"Salutation": null,
"Marital_Status_1": null,
"Birthday_1": null,
"First_Name": null,
"Full_Name": "Sam",
"Lead_Status": null,
"Record_Image": null,
"Modified_By": {
"name": "Patricia Boyle",
"id": "1306462000000374001",
"email": "p.boyle@abc.com"
},
"$review": null,
"Skype_ID": null,
"Phone": null,
"Lead_Class": "Class S",
"Email_Opt_Out": false,
"Designation": null,
"Modified_Time": "2022-02-03T10:55:15+05:30",
"$converted_detail": {},
"Unsubscribed_Time": null,
"Referred_By": null,
"Mobile": null,
"$orchestration": false,
"$stop_processing": false,
"Last_Name": "Sam",
"$in_merge": false,
"Lead_Source": null,
"Tag": [],
"Fax": null,
"$approval_state": "approved"
}
]
}
Converted Records
To retrieve the converted records, the converted parameter should be true or both. The converted_detail key in the response renders the conversion details which includes the deal (deal id), convert_date, contact (converted contact id), converted_by and account (account id). Please refer to the sample response for more details.
Possible Errors
- INVALID_MODULEHTTP 400
The module name given seems to be invalid
Resolution: You have specified an invalid module name or there is no tab permission, or the module could have been removed from the available modules. Specify a valid module API name. - INVALID_MODULEHTTP 400
The given module is not supported in API
Resolution: The modules such as Documents and Projects are not supported in the current API. (This error will not be shown, once these modules are been supported). Specify a valid module API name. - INVALID_MODULEHTTP 400
Territory is not supported for the given module
Resolution: The module you have specified is not territory-supported. Territory is supported only for the modules Deals, Contacts, and Accounts. - NOT_SUPPORTEDHTTP 403
This API is supported only for admin users
Resolution: Only admin users can fetch records from the Notes module. - INVALID_URL_PATTERNHTTP 404
Please check if the URL trying to access is a correct one
Resolution: The request URL specified is incorrect. Specify a valid request URL. Refer to request URL section above. - OAUTH_SCOPE_MISMATCHHTTP 401
Unauthorized
Resolution: Client does not have ZohoCRM.modules.{module_name}.READ scope. Create a new client with valid scope. Refer to scope section above. - NO_PERMISSIONHTTP 403
Permission denied to read
Resolution: The user does not have permission to read records data. Contact your system administrator. - INTERNAL_ERRORHTTP 500
Internal Server Error
Resolution: Unexpected and unhandled exception in Server. Contact support team. - INVALID_REQUEST_METHODHTTP 400
The http request method type is not a valid one
Resolution: You have specified an invalid HTTP method to access the API URL. Specify a valid request method. Refer to endpoints section above. - AUTHORIZATION_FAILEDHTTP 400
User does not have sufficient privilege to read records data
Resolution: The user does not have the permission to retrieve modules data. Contact your system administrator. - PATTERN_NOT_MATCHEDHTTP 400
Please check whether the input values are correct
Resolution: The value specified for one of the parameters is incorrect. Refer to parameters section above and specify valid parameter values.
Sample Request
Copiedcurl "https://www.zohoapis.com/crm/v2/Leads?converted=true&approved=true"
-X GET
-H "Authorization: Zoho-oauthtoken 1000.8cb99dxxxxxxxxxxxxx9be93.9b8xxxxxxxxxxxxxxxf"
Sample Response
Copied{
"data": [
{
"Owner": {
"name": "Patricia Boyle",
"id": "1306462000000374001",
"email": "p.boyle@abc.com"
},
"Company": null,
"Email": "j.smith@xyz.com",
"$currency_symbol": "$",
"$field_states": null,
"Last_Activity_Time": "2021-10-05T14:37:26+05:30",
"Industry": "Service Provider",
"$state": "save",
"Unsubscribed_Mode": null,
"$converted": true,
"$process_flow": false,
"Test": null,
"Street": "37275 St Rt 17m M",
"Data_Processing_Basis_Details": null,
"Zip_Code": "11953",
"id": "1306462000000391002",
"Data_Source": "API",
"$approved": true,
"$approval": {
"delegate": false,
"approve": false,
"reject": false,
"resubmit": false
},
"$data_source_details": {},
"Created_Time": "2021-08-24T14:52:07+05:30",
"$editable": true,
"City": "Middle Island",
"No_of_Employees": null,
"State": "NY",
"Country": "United States",
"Created_By": {
"name": "Patricia Boyle",
"id": "1306462000000374001",
"email": "p.boyle@abc.com"
},
"Annual_Revenue": 850000,
"Secondary_Email": null,
"Description": null,
"Rating": null,
"$review_process": {
"approve": false,
"reject": false,
"resubmit": false
},
"Website": "http://www.rangoniofflorence.com",
"Twitter": "christophermaclead_sample",
"Information": null,
"Salutation": "Mr.",
"Marital_Status_1": null,
"Birthday_1": null,
"First_Name": "Jim",
"Full_Name": "Mr. Jim Smith",
"Lead_Status": "Lost Lead",
"Record_Image": "02b9e93996ad174d0c685bd56b94e9d760497ba52e17145a73c18292ae60c1d81915036312ccaf1faaf8c8168eeff1cf427c96c3020bcd3da31280be451e09164c5ce0a2e1ff5d13109c3d1eac14bfdd",
"Modified_By": {
"name": "Patricia Boyle",
"id": "1306462000000374001",
"email": "p.boyle@abc.com"
},
"$review": null,
"Skype_ID": "christopher-maclead",
"Phone": "555-555-5555",
"Lead_Class": null,
"Email_Opt_Out": false,
"Designation": "VP Accounting",
"Modified_Time": "2021-10-05T14:37:26+05:30",
"$converted_detail": {
"deal": "1306462000000519017",
"convert_date": "2021-10-05T20:07:26+05:30",
"contact": "1306462000000396035",
"converted_by": "1306462000000374001",
"account": "1306462000000497010"
},
"Unsubscribed_Time": null,
"Referred_By": null,
"Mobile": "9400000001",
"$orchestration": false,
"$stop_processing": false,
"Last_Name": "Maclead (Sample)",
"$in_merge": false,
"Lead_Source": "Cold Call",
"Tag": [],
"Fax": "1234123415",
"$approval_state": "approved"
}
],
"info": {
"call": false,
"per_page": 200,
"count": 1,
"page": 1,
"email": false,
"more_records": false
}
}