Read email status metrics using COQL Query Builder (Emails module, v2)
Queries the Emails module via COQL for metrics such as status (bounced, opened, clicked), open/click times, bounce reason, and related fields. Zoho exposes Emails in COQL only through API v2; from v3 onward this approach does not apply. With v2, PageSize must be 200 or less. For other modules, use v7/v8 (or v3+) if you need page sizes larger than 200.
Standard SQL query example
This is the base query accepted by the connector. To execute it in SQL Server, you have to pass it to the Data Gateway via a Linked Server. See how to accomplish this using the examples below.
SELECT *
FROM get_module_data_coql_builder
WITH(
Module='Emails'
, Version='v2' --must be v2 for Emails module , newer versions dont support Emails module in COQL
, Select='Owner,Subject,Entity_Id,Modified_By,Created_Time,Modified_Time,Sent_To,Module,Last_Opened,Last_Clicked,Bounced_Time,First_Opened,First_Clicked,No_of_Opens,No_of_Clicks,Template_Name,Sent_On,Status,Source,Cc,Sender,Bounce_Reason,Bcc'
--, Where='Status = ''Bounced'' and Created_Time>''2015-07-08T03:07:16-04:00'' '
--, OrderBy='Created_Time desc'
)
Using OPENQUERY in SQL Server
SELECT * FROM OPENQUERY([LS_TO_ZOHO_CRM_IN_GATEWAY], 'SELECT *
FROM get_module_data_coql_builder
WITH(
Module=''Emails''
, Version=''v2'' --must be v2 for Emails module , newer versions dont support Emails module in COQL
, Select=''Owner,Subject,Entity_Id,Modified_By,Created_Time,Modified_Time,Sent_To,Module,Last_Opened,Last_Clicked,Bounced_Time,First_Opened,First_Clicked,No_of_Opens,No_of_Clicks,Template_Name,Sent_On,Status,Source,Cc,Sender,Bounce_Reason,Bcc''
--, Where=''Status = ''''Bounced'''' and Created_Time>''''2015-07-08T03:07:16-04:00'''' ''
--, OrderBy=''Created_Time desc''
)')
Using EXEC in SQL Server (handling larger SQL text)
The major drawback of OPENQUERY is its inability to incorporate variables within SQL statements.
This often leads to the use of cumbersome dynamic SQL (with numerous ticks and escape characters).
Fortunately, starting with SQL 2005 and onwards, you can utilize the EXEC (your_sql) AT [LS_TO_ZOHO_CRM_IN_GATEWAY] syntax.
DECLARE @MyQuery NVARCHAR(MAX) = 'SELECT *
FROM get_module_data_coql_builder
WITH(
Module=''Emails''
, Version=''v2'' --must be v2 for Emails module , newer versions dont support Emails module in COQL
, Select=''Owner,Subject,Entity_Id,Modified_By,Created_Time,Modified_Time,Sent_To,Module,Last_Opened,Last_Clicked,Bounced_Time,First_Opened,First_Clicked,No_of_Opens,No_of_Clicks,Template_Name,Sent_On,Status,Source,Cc,Sender,Bounce_Reason,Bcc''
--, Where=''Status = ''''Bounced'''' and Created_Time>''''2015-07-08T03:07:16-04:00'''' ''
--, OrderBy=''Created_Time desc''
)'
EXEC (@MyQuery) AT [LS_TO_ZOHO_CRM_IN_GATEWAY]