Zoho Analytics & Zoho People: Monitor DataSource Sync

Zoho Analytics & Zoho People: Monitor DataSource Sync

What?
A quick article on how to setup an automation that checks if a datasource synchronization between Zoho People and Zoho Analytics failed. This can be adapted to any data source for Zoho Analytics.

Why?
We're assisting a client implement Zoho People as their new HR solution. Zoho Analytics is used to generate specific spreadsheets for a feed into their third-party payroll system. If the data is incorrect in Zoho Analytics, and payroll gets run with these discrepancies, then they will have a fair few disgruntled employees who may have been paid incorrectly. As such this system has to be reliable and the system managers need to be notified in advance of any errors with the intention to be able to correct any inconsistencies themselves.

How?
We're going to add a scheduled workflow on a daily basis at 1am in the morning every day. This will be added to the client's Zoho People instance which will check the datasource metadata via the Analytics API.

Add a custom scheduler in Zoho People
  1. Login to ZohoPeople as a system administrator
  2. Click on the cog icon in the top right to go to the setup screen.
  3. Under "Automation", click on "Scheduler"
  4. Click on the "Add Scheduler" button
  5. Complete the "Scheduler" header information such as the name, description, start date/time, frequency, and timezone.
  6. While you're here, click on "Connections" at the top of the IDE (where you paste the code) and ensure you setup a Connection that does NOT use the credentials of the logged-in user and has as scope ZohoAnalytics.metadata.read.

The code
copyraw
/* *******************************************************************************
Function:       void Check_DataSources_Sync_to_ZohoAnalytics ()
Label:          Check DataSources Sync to ZohoAnalytics
Trigger:        Scheduled daily at 1am starting from tomorrow (3-Jul-2024)
Purpose:		To warn system managers if a sync started failing.
Inputs:         None
Outputs:        Emails system manager if any failures.

Date Created:   2024-07-02 (JoelLipman.com - Joel Lipman)
                - Initial release
Date Modified:	???
                - ???

More Information:
                https://www.zoho.com/analytics/api/v2/metadata-api/datasources.html

******************************************************************************* */
//
// initialize
v_LastSyncTime = null;
v_LastSyncStatus = "?";
m_DataSourceInfo = Map();
//
// read the TLD (eu or com or com.in) from the URL when logged into Zoho Analytics
v_BaseURL = "https://analyticsapi.zoho.com";
//
// to get workspace ID, look at the URL in ZohoAnalytics and take the number straight after the word "workspace/"
v_WorkspaceID = "12345000001234567";
//
// to get the Analytics Org ID, login to Zoho Analytics, ensuring you are on the "Home" page (click on "Home" in top menu if not),
// then click on the cog icon "Organization Settings", then click on "Organization Details",
// then look at the URL (website address) and take the number directly after "org-details/"
v_AnalyticsOrgID = "20240702123";
//
// generate request header
m_Header = Map();
m_Header.put("ZANALYTICS-ORGID",v_AnalyticsOrgID);
//
// generate the endpoint to read the analytics metadata on the syncs
v_Endpoint = v_BaseURL + "/restapi/v2/workspaces/" + v_WorkspaceID + "/datasources";
//
// send the request
r_Analytics = invokeurl
[
	url :v_Endpoint
	type :GET
	headers:m_Header
	connection:"my_connection"
];
//info r_Analytics;
//
// parse response
if(r_Analytics.get("status") == "success")
{
	m_ResponseData = ifnull(r_Analytics.get("data"),Map());
	l_DataSources = ifnull(m_ResponseData.get("dataSources"),List());
	for each  m_DataSource in l_DataSources
	{
		if(m_DataSource.get("datasourceName").equalsIgnoreCase("Zoho People"))
		{
			v_LastSyncTime = m_DataSource.get("lastDataSyncTime");
			v_LastSyncStatus = m_DataSource.get("lastDataSyncStatus");
			m_DataSourceInfo = m_DataSource;
			break;
		}
	}
}
//info m_DataSourceInfo;
//
// to email or not to email, that is the question, whether 'tis nobler in the mind to suffer...
if(!v_LastSyncStatus.equalsIgnoreCase("Data Sync Successful"))
{
	v_To = "Client <my_client@their_company.com>";
	v_Cc = {"Joel Lipman Support Desk <This email address is being protected from spambots. You need JavaScript enabled to view it.>"};
	v_Subject = "URGENT: Sync Between Zoho People and Zoho Analytics Failed!!!";
	v_Message = "Hi there!<br /><br />This is an email to advise that the synchronization between your Zoho People and Zoho Analytics instances failed.  The last synchronization data we have is as follows:<br /><br /><table style='margin:0 auto;'>";
	if(!isNull(m_DataSourceInfo.get("datasourceName")))
	{
		for each  v_DataSourceKey in m_DataSourceInfo.keys()
		{
			v_Message = v_Message + "<tr><td>" + v_DataSourceKey + "</td><td>" + ifnull(m_DataSourceInfo.get(v_DataSourceKey),"?") + "</td></tr>";
		}
	}
	else
	{
		v_Message = v_Message + "<tr><td><b>No Datasource Information!</b> Either the data source synchronization has been switched off or there is an error with a connection account between Zoho People and Zoho Analytics.</td></tr>";
	}
	v_Message = v_Message + "</table><br />This may have been a one-off blip but if you get this error again tomorrow, you should raise this with either Zoho or your Zoho partner.  This email will also have been copied to the ticket support system of your Zoho Partner.<br /><br />Kind Regards,<br /><br /><b>the Joel Lipman team</b><br /><a href='mailto:This email address is being protected from spambots. You need JavaScript enabled to view it.'>This email address is being protected from spambots. You need JavaScript enabled to view it.</a><br /><a href='https://joellipman.com'>www.joellipman.com</a>";
	sendmail
	[
		from :zoho.adminuserid
		to :v_To
		cc:v_Cc
		subject :v_Subject
		message :v_Message
	]
}
  1.  /* ******************************************************************************* 
  2.  Function:       void Check_DataSources_Sync_to_ZohoAnalytics () 
  3.  Label:          Check DataSources Sync to ZohoAnalytics 
  4.  Trigger:        Scheduled daily at 1am starting from tomorrow (3-Jul-2024) 
  5.  Purpose:        To warn system managers if a sync started failing. 
  6.  Inputs:         None 
  7.  Outputs:        Emails system manager if any failures. 
  8.   
  9.  Date Created:   2024-07-02 (JoelLipman.com - Joel Lipman) 
  10.                  - Initial release 
  11.  Date Modified:    ??? 
  12.                  - ??? 
  13.   
  14.  More Information: 
  15.                  https://www.zoho.com/analytics/api/v2/metadata-api/datasources.html 
  16.   
  17.  ******************************************************************************* */ 
  18.  // 
  19.  // initialize 
  20.  v_LastSyncTime = null
  21.  v_LastSyncStatus = "?"
  22.  m_DataSourceInfo = Map()
  23.  // 
  24.  // read the TLD (eu or com or com.in) from the URL when logged into Zoho Analytics 
  25.  v_BaseURL = "https://analyticsapi.zoho.com"
  26.  // 
  27.  // to get workspace ID, look at the URL in ZohoAnalytics and take the number straight after the word "workspace/" 
  28.  v_WorkspaceID = "12345000001234567"
  29.  // 
  30.  // to get the Analytics Org ID, login to Zoho Analytics, ensuring you are on the "Home" page (click on "Home" in top menu if not), 
  31.  // then click on the cog icon "Organization Settings", then click on "Organization Details", 
  32.  // then look at the URL (website address) and take the number directly after "org-details/" 
  33.  v_AnalyticsOrgID = "20240702123"
  34.  // 
  35.  // generate request header 
  36.  m_Header = Map()
  37.  m_Header.put("ZANALYTICS-ORGID",v_AnalyticsOrgID)
  38.  // 
  39.  // generate the endpoint to read the analytics metadata on the syncs 
  40.  v_Endpoint = v_BaseURL + "/restapi/v2/workspaces/" + v_WorkspaceID + "/datasources"
  41.  // 
  42.  // send the request 
  43.  r_Analytics = invokeUrl 
  44.  [ 
  45.      url :v_Endpoint 
  46.      type :GET 
  47.      headers:m_Header 
  48.      connection:"my_connection" 
  49.  ]
  50.  //info r_Analytics; 
  51.  // 
  52.  // parse response 
  53.  if(r_Analytics.get("status") == "success") 
  54.  { 
  55.      m_ResponseData = ifnull(r_Analytics.get("data"),Map())
  56.      l_DataSources = ifnull(m_ResponseData.get("dataSources"),List())
  57.      for each  m_DataSource in l_DataSources 
  58.      { 
  59.          if(m_DataSource.get("datasourceName").equalsIgnoreCase("Zoho People")) 
  60.          { 
  61.              v_LastSyncTime = m_DataSource.get("lastDataSyncTime")
  62.              v_LastSyncStatus = m_DataSource.get("lastDataSyncStatus")
  63.              m_DataSourceInfo = m_DataSource; 
  64.              break
  65.          } 
  66.      } 
  67.  } 
  68.  //info m_DataSourceInfo; 
  69.  // 
  70.  // to email or not to email, that is the question, whether 'tis nobler in the mind to suffer... 
  71.  if(!v_LastSyncStatus.equalsIgnoreCase("Data Sync Successful")) 
  72.  { 
  73.      v_To = "Client <my_client@their_company.com>"
  74.      v_Cc = {"Joel Lipman Support Desk <This email address is being protected from spambots. You need JavaScript enabled to view it.>"}
  75.      v_Subject = "URGENT: Sync Between Zoho People and Zoho Analytics Failed!!!"
  76.      v_Message = "Hi there!<br /><br />This is an email to advise that the synchronization between your Zoho People and Zoho Analytics instances failed.  The last synchronization data we have is as follows:<br /><br /><table style='margin:0 auto;'>"
  77.      if(!isNull(m_DataSourceInfo.get("datasourceName"))) 
  78.      { 
  79.          for each  v_DataSourceKey in m_DataSourceInfo.keys() 
  80.          { 
  81.              v_Message = v_Message + "<tr><td>" + v_DataSourceKey + "</td><td>" + ifnull(m_DataSourceInfo.get(v_DataSourceKey),"?") + "</td></tr>"
  82.          } 
  83.      } 
  84.      else 
  85.      { 
  86.          v_Message = v_Message + "<tr><td><b>No Datasource Information!</b> Either the data source synchronization has been switched off or there is an error with a connection account between Zoho People and Zoho Analytics.</td></tr>"
  87.      } 
  88.      v_Message = v_Message + "</table><br />This may have been a one-off blip but if you get this error again tomorrow, you should raise this with either Zoho or your Zoho partner.  This email will also have been copied to the ticket support system of your Zoho Partner.<br /><br />Kind Regards,<br /><br /><b>the Joel Lipman team</b><br /><a href='mailto:This email address is being protected from spambots. You need JavaScript enabled to view it.'>This email address is being protected from spambots. You need JavaScript enabled to view it.</a><br /><a href='https://joellipman.com'>www.joellipman.com</a>"
  89.      sendmail 
  90.      [ 
  91.          from :zoho.adminuserid 
  92.          to :v_To 
  93.          cc:v_Cc 
  94.          subject :v_Subject 
  95.          message :v_Message 
  96.      ] 
  97.  } 


Category: Zoho :: Article: 876

Please publish modules in offcanvas position.