Skip to product menu
close
  • Sales
    Press Space or Enter to display list of options
EXPLORE ALL PRODUCTS

Sales

 
CRM

Comprehensive CRM platform for customer-facing teams.

CRM
 
Bigin

Simple CRM for small businesses moving from spreadsheets.

Bigin
 
Forms

Build online forms for every business need.

Forms
 
SalesIQ

Live chat app to engage and convert website visitors.

SalesIQ
 
Bookings

Appointment scheduling app for consultations with customers.

Bookings
 
Sign

Digital signature app for businesses.

Sign
 
RouteIQ

Comprehensive sales map visualization and optimal route planning solution.

RouteIQ
 
Thrive

Complete loyalty and affiliate management platform.

Thrive
 
Voice

Cloud Contact Center Software for businesses.

Voice
 
Suites
CRM Plus

Unified platform to deliver top-notch customer experience.

CRM Plus

Marketing

 
Social

All-in-one social media management software.

Social
 
Campaigns

Create, send, and track targeted email campaigns that drive sales.

Campaigns
 
Forms

Build online forms for every business need.

Forms
 
Survey

Design surveys to reach and interact with your audience.

Survey
 
Sites

Online website builder with extensive customisation options.

Sites
 
PageSense

Website conversion optimization and personalisation platform.

PageSense
 
Backstage

End-to-end event management software.

Backstage
 
Webinar

Webinar platform for webcasting online webinars.

Webinar
 
Marketing Automation

All-in-one marketing automation software.

Marketing Automation
 
LandingPage

Smart landing page builder to increase conversion rates

LandingPage
 
Publish

Manage all your local business listings on a single platform.

Publish
 
SalesIQ

Live chat app to engage and convert website visitors.

SalesIQ
 
Sign

Digital signature app for businesses.

Sign
 
Thrive

Complete loyalty and affiliate management platform.

Thrive
 
Voice

Cloud Contact Center Software for businesses.

Voice
 
NEW
LeadChain

Sync, manage, and convert leads across channels seamlessly.

LeadChain
 
NEW
CommunitySpaces

Online community platform for individuals and businesses to grow their network and brand.

CommunitySpaces
 
Suites
Marketing Plus

Unified marketing platform for marketing teams.

Marketing Plus

Commerce and POS

 
Commerce

eCommerce platform to manage and market your online store.

Commerce

Service

 
Desk

Helpdesk software to deliver great customer support.

Desk
 
Assist

Remote support and unattended remote access software.

Assist
 
Lens

Interactive remote assistance software with augmented reality.

Lens
 
FSM

End-to-end field service management platform for service businesses.

FSM
 
SalesIQ

Live chat app to engage and convert website visitors.

SalesIQ
 
Voice

Cloud Contact Center Software for businesses.

Voice
 
Solo

The all-in-one toolkit for solopreneurs.

Solo
 
Bookings

Appointment scheduling app for consultations with customers.

Bookings
 
Suites
Service Plus

Unified platform for customer service and support teams.

Service Plus

Finance

 
Books

Powerful accounting platform for growing businesses.

Books
 
FREE
Invoice

100% Free invoicing solution.

Invoice
 
Expense

Effortless expense reporting platform.

Expense
 
Inventory

Powerful stock management and inventory control software.

Inventory
 
Billing

End-to-end billing solution for your business.

Billing
 
Checkout

Collect payments online with custom branded pages.

Checkout
 
NEW
Payroll

Payroll software with automated tax payments and filing.

Payroll
 
Solo

The all-in-one toolkit for solopreneurs.

Solo
 
Practice

Practice management software for accounting firms.

Practice
 
Sign

Digital signature app for businesses.

Sign
 
Commerce

eCommerce platform to manage and market your online store.

Commerce
 
Suites
Finance Plus

All-in-one suite to manage your operations and finances.

Finance Plus

Email and Collaboration

 
Mail

Secure email service for teams of all sizes.

Mail
 
Meeting

Online meeting software for all your video conferencing & webinar needs.

Meeting
 
Writer

Word processor for focused writing and discussions.

Writer
 
Sheet

Spreadsheet software for collaborative teams.

Sheet
 
Show

Create, edit, and share slides with a sleek presentation app.

Show
 
Notebook

Beautiful home for all your notes.

Notebook
 
Cliq

Stay in touch with teams no matter where you are.

Cliq
 
Connect

Employee experience platform to communicate, engage, and build positive employee relations.

Connect
 
Bookings

Appointment scheduling app for consultations with customers.

Bookings
 
TeamInbox

Shared inboxes for teams.

TeamInbox
 
WorkDrive

Online file management for teams.

WorkDrive
 
Sign

Digital signature app for businesses.

Sign
 
Office Suite

Powerful collaborative work platform for teams.

Office Suite
 
Office Integrator

Built in document editors for web apps.

Office Integrator
 
ZeptoMail

Secure and reliable transactional email sending service.

ZeptoMail
 
Calendar

Online business calendar to manage events and schedule appointments.

Calendar
 
Learn

Knowledge and learning management platform.

Learn
 
Voice

Cloud Contact Center Software for businesses.

Voice
 
ToDo

Collaborative task management for individuals and teams.

ToDo
 
Tables

Work management tool to connect people, processes, and information.

Tables
 
FREE
PDF Editor

Collaborative online PDF editing tool.

PDF Editor
 
Suites
Workplace

Application suite built to improve team productivity and collaboration.

Workplace

Human Resources

 
People

Organize, automate, and simplify your HR processes.

People
 
Recruit

Intuitive recruiting platform built to provide hiring solutions.

Recruit
 
Expense

Effortless expense reporting platform.

Expense
 
Workerly

Manage temporary staffing with an employee scheduling solution.

Workerly
 
NEW
Payroll

Payroll software with automated tax payments and filing.

Payroll
 
Shifts

Employee scheduling and time tracking app.

Shifts
 
Sign

Digital signature app for businesses.

Sign
 
Suites
People Plus

Comprehensive HR platform for seamless employee experiences.

People Plus

Security and IT Management

 
Creator

Build custom apps to simplify business processes.

Creator
 
Directory

Workforce identity and access management solution for cloud businesses.

Directory
 
FREE
OneAuth

Secure multi-factor authenticator (MFA) for all your online accounts.

OneAuth
 
Vault

Online password manager for teams.

Vault
 
Catalyst

Pro-code platform to build and deploy your apps.

Catalyst
 
Toolkit

Complete resource for any admin-related lookup queries.

Toolkit
 
Lens

Interactive remote assistance software with augmented reality.

Lens
 
Assist

Remote support and unattended remote access software.

Assist
 
QEngine

Test automation software to build, manage, execute, and report testcases.

QEngine
 
NEW
RPA

Automate manual, tedious, and repetitive tasks easily.

RPA

BI and Analytics

 
Analytics

Modern self-service BI and analytics platform.

Analytics
 
Embedded BI

Embedded analytics and white label BI solutions, tailored for your needs.

Embedded BI
 
DataPrep

AI-powered data preparation service for your data-driven organization.

DataPrep
 
NEW
IoT

Harnessing IoT analytics for real-time operational intelligence.

IoT

Project Management

 
Projects

Manage, track, and collaborate on projects with teams.

Projects
 
Sprints

Planning and tracking tool for scrum teams.

Sprints
 
BugTracker

Automatic bug tracking software for managing bugs.

BugTracker
 
Solo

The all-in-one toolkit for solopreneurs.

Solo

Developer Platforms

 
Creator

Build custom apps to simplify business processes.

Creator
 
Flow

Automate business workflows by creating smart integrations.

Flow
 
Catalyst

Pro-code platform to build and deploy your apps.

Catalyst
 
Office Integrator

Built in document editors for web apps.

Office Integrator
 
ZeptoMail

Secure and reliable transactional email sending service.

ZeptoMail
 
QEngine

Test automation software to build, manage, execute, and report testcases.

QEngine
 
Tables

Work management tool to connect people, processes, and information.

Tables
 
NEW
RPA

Automate manual, tedious, and repetitive tasks easily.

RPA
 
NEW
Apptics

Application analytics for all apps.

Apptics
 
Embedded BI

Embedded analytics and white label BI solutions, tailored for your needs.

Embedded BI
 
NEW
IoT

Build, deploy, and scale IoT solutions for connected businesses.

IoT
 
DataPrep

AI-powered data preparation service for your data-driven organization.

DataPrep

IoT

 
NEW
IoT

Low-code IoT platform and solutions for connected businesses.

IoT

Search Result

 
CRM Plus

Unified platform to deliver top-notch customer experience.

Try now
CRM Plus
 
Service Plus

Unified platform for customer service and support teams.

Try now
Service Plus
 
Finance Plus

All-in-one suite to manage your operations and finances.

Try now
Finance Plus
 
People Plus

Comprehensive HR platform for seamless employee experiences.

Try now
People Plus
 
Workplace

Application suite built to improve team productivity and collaboration.

Try now
Workplace
 
Marketing Plus

Unified marketing platform for marketing teams.

Try now
Marketing Plus
 
All-in-one suite

Zoho One

The Operating System for Business

Run your entire business on Zoho with our unified cloud software, designed to help you break down silos between departments and increase organizational efficiency.

TRY ZOHO ONE
Zoho One
Zoho Marketplace

With over 2000 ready-to-use extensions across 40+ categories, connect your favorite business tools with the Zoho products you already use.

EXPLORE MARKETPLACE
Marketplace
Skip to main content

Query API - An Overview

COQL, abbreviated for CRM Object Query Language, allows users to write SQL-like queries to fetch records from Zoho CRM. Like SQL that uses table names, Query API uses module and field API names in the query.
While Search API allows module-specific search, Query API allows you to retrieve records from cross-modules that are linked via lookup fields, thereby establishing joins.

Table of Contents

Syntax and Supported Clauses

Query API supports the SELECT query and the following clauses that you can use to apply conditions and retrieve records based on them from a module. In the SELECT column, you must use field API name as column names.

  • SELECT - This statement is to select the fields you want to receive in the response. You can specify up to 50 field API names in the SELECT column of the query. You can use the Field Metadata API to get the API name of a field in a module, or go to Setup > Developer Hub > APIs and SDKs, and click the API Names tab. Choose the required module from the list of available modules and look for the API name of the desired field.
  • WHERE - This clause is to specify the condition or criteria to filter and fetch records. You can include up to 25 criteria in this clause. Ensure to enclose the criteria in brackets properly to achieve the desired results.
  • FROM - This clause is to specify the module's API name from which you want to retrieve records. To retrieve records from a Subform, specify the Subform module's API name. Similarly, for queries with multi-select lookup fields, query to the linking module.
  • ORDER BY - Use this clause to sort the records in the response based on specific fields either in ascending or descending order. The default sorting is based on record ID in the ascending order.
  • LIMIT and OFFSET - The LIMIT clause is to specify the number of matching records you want to receive in the response. The default value is 200 and the max value is 2000.
    OFFSET is to paginate through records. For example, if you have set this value as 10, then the system skips the first ten matching records, and retrieves the others from the 11th index.
    In COQL, the syntax is LIMIT offset, limit. The first value is the offset, while the next one is the limit.
  • GROUP BY - Use this clause to retrieve data from a table by specifying the field API names as conditions in a query and group them. It helps you filter and organize the records efficiently, and group the results of a query based on one or more columns as objects in the response. In general, you can use this clause with both aggregate and non-aggregate functions.

Syntax

Here is the syntax of a COQL query.

SELECT field_api_name1, field_api_name2
                    FROM base_module_api_name
                    WHERE field_api_name comparator logical_operator field_api_name comparator
                    ORDER BY field_api_name ASC/DESC
                    LIMIT offset, limit

Here is a sample SQL query and it's equivalent COQL query. In the query, we want to fetch the Last_Name, Created_Time fields from the Leads module. The WHERE clause has the condition. This query sorts the records in the response based on Created_Time and record ID in the ascending order as specified in the ORDER BY clause. The offset is 10 and the limit is 2, meaning that the first 10 matching records are skipped, and the next two records are retrieved in the response. 
 

SELECT Last_Name, Created_Time
                    FROM Leads
                    WHERE Last_Name IS NOT NULL 
                      AND Created_Time >= '2019-02-19T12:57:55+05:30'
                    GROUP BY Last_Name, Created_Time
                    ORDER BY Created_Time, id ASC
                    LIMIT 10 OFFSET 2;

Equivalent COQL query

{
        "select_query" : "select Last_Name, Created_Time from Leads where (Last_Name is not null and Created_Time >= '2019-02-19T12:57:55+05:30')  group by Last_Name, Created_Time order by Created_Time, id asc limit 10, 2"
        }

Response

{
        "data": [
            {
                "Last_Name": "Smith",
                "Created_Time": "2019-11-26T12:09:48+05:30"
            },
            {
                "Last_Name": "Gerald",
                "Created_Time": "2019-11-26T12:10:43+05:30"
            }
        ],
        "info": {
            "count": 2,
            "more_records": true
        }
    }
    

Fields and Criteria

The main aim of querying for records is to filter them based on some criteria. Query API lets you apply multiple criteria to various fields in the WHERE clause. When the criteria are satisfied, the matching records are rendered in the response.

Consider this simple query.

{
        "select_query":"select Last_Name, Company, Lead_Status from Leads where (Lead_Status = Contacted and Last_Name is not null) limit 2 "
    }
    

In this query, Last_Name, Company, and Lead_Status are the API names of the fields in the Leads module that we want to be retrieved in the response.
The WHERE clause contains the condition that the Lead_Status must have the value Contacted and the Last_Name must not be null. The = and is not null are the comparators for the respective fields. and is the group operator applied over the criteria.

Like this, you can have a maximum of 25 criteria in your WHERE clause. Meaning, if your WHERE clause looks like ((A and B) and C)), it means there are three conditions/criteria applied over three fields or the same fields. This way, you can have up to 25 criteria applied over different fields or same field in the WHERE clause.

Every field type(data type) can be used with its own set of comparators. Refer to the Get Records through a COQL query page for details and examples about each field type.

Alias support

You can see in the above response that the key names are long. If you want to have them short or have names that make more sense to you, you can use the alias support in COQL. Use the keyword AS(case-insensitive) in your query to customize the key names in the response. Here is a sample.

{
    "select_query":"select 'Account_Name' AS 'Account id','Account_Name.Account_Name' as 'Account Name','Account_Name.Parent_Account' as 'Parent Account id','Account_Name.Parent_Account.Account_Name' As 'Parent Account Name' from Contacts where (Account_Name.Parent_Account.Account_Name = 'King') limit 1"
    }

Response

{
    "data": [
        {
            "Account id": {
                "id": "3652397000000624046"
            },
            "Account Name": "Zylker",
            "Parent Account id": {
                "id": "3652397000000190102"
            },
            "Parent Account Name": "King",
            "id": "3652397000000269089"
        }
    ],
    "info": {
        "count": 1,
        "more_records": true
    }
}

GROUP BY and Aggregate Functions

As discussed in the Syntax and Supported Clauses section, GROUP BY clause is to filter and organize the records efficiently, and group the results of a query based on one or more columns as objects in the response. You can use the GROUP BY clause on both aggregate and non-aggregate functions.

Aggregate Functions

The advantage of using aggregate functions in the COQL API in Zoho CRM is that they allow for powerful data analyses directly within CRM. Aggregate functions like SUM(), AVG(), COUNT(), MIN(), and MAX() enable you to perform calculations on data, such as finding totals, averages, and other statistical measures.
This capability helps in generating insights and reports without the need to export data to external tools, thus improving efficiency and decision-making processes within the CRM environment. 
Refer to the Get Records through a COQL query page for details and examples about each aggregate function.

Pagination

With Query API, you can retrieve up to 2000 records per API call using LIMIT 0, 2000. This fetches the first 2000 records that match the criteria in the WHERE clause. 
When you want to fetch more records, you can use OFFSET with the LIMIT clause. For example, LIMIT 2000, 1500 will fetch the 1500 records from the 2001th index, that is, it skips the records in the index 1-2000.
With the same criteria, you can paginate up to 1,00,000 records. For the next set of records, add another criteria id > {last_record_id} with the "AND" operator, and go on to fetch the next 1,00,000 records. If you have custom sorting in your query, adjust the criteria accordingly. In the following example, sorting is done based on Created_Time and ID fields.

Query 1

{
"select_query" : "select Last_Name, Created_Time from Leads where Last_Name is not null order by Created_Time, id asc limit 0, 200"
}

When you use the above query and change the value of OFFSET(at 98,000), you can retrieve records from the 98,001-1,00,000th index. 
Note down the created time and ID of the last record in the response. To fetch records more than the previously fetched 1,00,000, you must construct a query to retrieve records that were created after the 1,00,000 record and whose record ID is greater than that of the 1,00,000th record's.

Query 2

{
"select_query" : "select Last_Name, Created_Time from Leads where ((Last_Name is not null and Created_Time > '2019-11-26T12:14:52+05:30') and id > 3652397000001257649) order by Created_Time, id asc limit 0, 10"
}

Notes

  • COQL keywords are not case-sensitive, except for aggregate functions. SELECT is the same as select.
  • By default, the system sorts the records in ascending order based on the record ID, if you do not include order by in the query.
  • You can retrieve a maximum of 1,00,000 records in multiple API calls per unique criteria. If you want to retrieve more than 1,00,000 records, use the Bulk Read API.
  • API Credits are based on the value of LIMIT.
    • LIMIT between 1-200 - 1 API credit
    • LIMIT between 201-1000 - 2 API credits
    • LIMIT between 1001-2000 - 3 API credits
  • When constructing queries, it is crucial to parse special characters and SQL reserved words properly to avoid issues. They should be enclosed within quotes for proper handling.

    Similarly, when using an SQL-reserved keyword in the SELECT query, it should be enclosed in quotes. Here's an example of the correct usage where Dynamic, an SQL-reserved keyword, is used in a query:

    {
    "select_query": "select Last_Name, 'Dynamic' from Contacts where Last_Name is not null limit 2"
    }