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 Create Query.
- In the "Create Query" pop up, enter the following details:
- Enter Query Name and API Name. Click Next.
- Under Configuration, the default query type will be Zoho CRM Module. To change the type, click Change.
- 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.
- None - This option does not apply any 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. Dynamic value means that the value will be taken for this field when the query is used at some place. In this example, we are assigning a variable to get the ID of the contact record that is associated with the deal that meets the criteria.
- Record ID - Choose this option if you want to apply the query to a specific record. You can assign a variable to this field and pass the record ID during execution.
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 Execute Query. If your query has a dynamic value in criteria, you will get a pop up asking for its value. Specify the value and click Next. You will see the response of the query you created.
After the query executes, you can see the Schema at the bottom of the screen. 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 Create Query.
- In the "Create Query" window, under Configuration, enter the following details:
- By default, the type will be Zoho CRM Module. Click Change to choose another type of query. Select Zoho CRM COQL.
- Click Done.
Enter the COQL query. You can refer to the Get Records through a COQL query for details on constructing a query. Click Next.
- Click Add Serializer if you want to serialize the output of the query.
- Click Execute Query to execute and see the response.
- At the bottom of the screen, you can see the Schema.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 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.
- Click Create Query.
- By default, the type will be Zoho CRM Module. Click Change to choose another type of query. Select REST API.
- Select the source of your query from Source.
- Enter the endpoint of the external source to fetch data from and any parameters and headers for the request.
- If you want to serialize the response, click Add Serializer.
- Click Execute Query to see the response.
Under Schema, 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.