Types of Queries
Queries depend on the type of the source. Currently, there are the following types of Sources:
Based on the source, the configuration of the query varies, i.e, for the COQL source, you must form a query using CRM's Object Query Language that is similar to SQL's select query.
To build a module-specific query and use data from a specific module, you must choose the Modules source.
For REST API type, you should give an endpoint, required headers, parameters, and connections.
CRM - Modules
Use this type when you want to create a query for data in a CRM module.
- Go to Setup -> Developer Hub -> Queries. The Queries window opens.
- Click Add Query.
- In the "Add Query" pop up, enter the following details:
- Under Source, choose the source of the query as CRM Module.
- Under Information, enter the name and API name. This API name will be referenced at places where the query is used.
Choose the module in CRM for which you want to create the query. You can also create queries for Subforms.
- If your module has lookup fields, you can also include them in your query. Choose the required lookups in the Related Module drop down. Note that you can choose a maximum of two fields in this drop down.
- Select the required fields for your query from the Fields drop down. Note that you can choose a maximum of 50 fields here.
Under Criteria, you can choose to get all records, or filter the response by the record ID or apply criteria.
Criteria - You can apply criteria over different fields for which you are creating the query. Criteria supports various comparators and you can also group the conditions using AND or OR operators. You can also choose to give the value for the criterion or choose a dynamic value by setting a variable. Dynamic value means that the value will be taken for this field when the query is used at some place.
- Under Serializer, click Add Serializer to modify the response through JavaScript. You can then use this modified response for further processing. The following image shows an example of a serialized response. Click Save.
- You can also sort the response based on a field either in the ascending or descending order. Under Advanced, choose the field to be sorted on in the Order by drop down and the order in which it has to be sorted.
- Click Next. If your query has a dynamic value in criteria, you will get a pop up asking for its value. Specify the value and click Save. You will see the response of the Queries query you created. Click Next.
- In the next pop up, you can see the Path, CRM Field Type, and the Label. Path indicates the JSON path in the response that the field is available in, CRM field type indicates it's field type in CRM such as long int, int, and the label indicates the label/name of the field. You can edit these values based on what you need in the query's response.
- Click Save to save your query.
COQL
COQL queries are based on CRM's Object Query Language. These queries use the Query API in Zoho CRM to fetch data.
Refer to Get Records through a COQL query for details on constructing this type of query, the various supported field types, their operators etc.
Follow these steps to create a query of the source type "COQL".
- Go to Setup -> Developer Hub -> Queries. The Queries window opens.
- Click Add Query.
- In the "Create Query" window, enter the following details:
- Under Source, choose the source of the query as CRM COQL.
- Under Information, enter the name and API name. This API name will be referenced at places where the query is used.
Enter the COQL query. You can refer to the Get Records through a COQL query for details on constructing a query. Click Next.
- You can see the sample response of the query. Click Next.
- In the next pop up, you can see the Path, CRM Field Type, and the Label. Path indicates the JSON path in the response that the field is available in, CRM field type indicates it's field type in CRM such as long int, int, and the label indicates the label/name of the field. You can edit these values based on what you need in the query's response.
REST API
You can create a query to fetch data from an external service and use it in Zoho CRM. For this, you must have added a source to Queries as discussed here. Follow these steps to create a query to use data from an external service.
- Go to Setup -> Developer Hub -> Queries. The Queries window opens.
- Click Add Query.
- In the "Add Query" pop up, enter the following details:
- Under Source, choose the external source you had added.
Under Information, enter the endpoint of the external source to fetch data from and any parameters and headers for the request. Note that for this type, you must have an active connection. Click Next.
- You can see the response of your query.
- In the next pop up, you can see the Path, CRM Field Type, and the Label. Path indicates the JSON path in the response that the field is available in, CRM field type indicates it's field type in CRM such as long int, int, and the label indicates the label/name of the field. You can edit these values based on what you need in the query's response.
- Click Save to save your query.