Skip to content

Latest commit

 

History

History
222 lines (151 loc) · 5.09 KB

README_OLD_VERSION.md

File metadata and controls

222 lines (151 loc) · 5.09 KB

Zoho Analytics Connector

Supported Versions License

Install

pip install requests
pip install sphinx
pip install .

Authentication

Zoho Analytics REST API supports OAuth 2.0 protocol to authorize and authenticate API calls. Follow the steps listed here to use OAuth 2.0 protocol in Zoho Analytics APIs.

The scope for full access

ZohoAnalytics.fullaccess.all

Import

from connector_analytics.analytics import zohoConnect

Config File

class Config:
    SERVERAUTH = ''
    SERVERURL = ''
    LOGINEMAILID = ''
    CLIENTID = ''
    CLIENTSECRET = ''
    REFRESHTOKEN = ''

 

Data Centre ZohoAnalytics_Server_URI ZohoAccounts_Server_URI
US (United States) analyticsapi.zoho.com accounts.zoho.com
EU (Europe) analyticsapi.zoho.eu accounts.zoho.eu
IN (India) analyticsapi.zoho.in accounts.zoho.in
AU (Australia) analyticsapi.zoho.com.au accounts.zoho.com.au
CN (China) analyticsapi.zoho.com.cn accounts.zoho.com.cn

 

Example for Config.py

class  Config:
	SERVERAUTH = 'https://accounts.zoho.com'
	SERVERURL = 'https://analyticsapi.zoho.com/api/user@domain.com/table'
	LOGINEMAILID = 'user@domain.com'
	CLIENTID = '******'
	CLIENTSECRET = '******'
	REFRESHTOKEN = '******'
	

Initialize Zoho Object

objZoho = zohoConnect(srvUrl=Config.SERVERAUTH,
					tokenToRefresh=Config.REFRESHTOKEN,
					clientId=Config.CLIENTID,
					clientSecret=Config.CLIENTSECRET)

Add Row

payload = {
	'Id':'1',
	'Name':'Armando Aguilar',
	'Cell':'52-55555-555',
	'Country':'CDMEX'}
	
objZoho.addRow(tableURL=Config.SERVERURL,columnsValues=payload)

Update Row

conditional = 'Id=1'

payload = {
	'Name':'Armando Aguilar L.',
	'Cell':'52-895578-6789',
	'Country':'UK'}

update = objZoho.updateRow(tableURL=Config.SERVERURL,
						updateInfo=payload,
						conditionalInfo=conditional)

Delete row

conditional = 'Id=1'
delete = objZoho.deleteRow(tableURL=Config.SERVERURL,
							conditionalInfo=conditional)

 

Work with multiple rows

 

CVS File

Use a simple cvs or format in a string to insert rows in the table of zoho in this example we used this files called users.cvs.

  • APPEND Appends the data into the table.
  • TRUNCATEADD - Deletes all exisiting rows in the table and adds the imported data as new entry.
  • UPDATEADD Updates the row if the mentioned column values are matched, else a new entry will be added.

 

ID Name Country
1 User 1 MX
2 User 2 CAD
3 User 3 UK
4 User 4 USA

 

with open('users.csv', 'r') as f:
	data = f.read()
	autoIdentify = "true"
	onError = "ABORT"

Add rows

APPEND Appends the data into the table.

Tip: ImportRows can be data of real csv file or string with the format cvs.

objZoho.ImportRows(tableURL= Config.SERVERURL,
					importType='APPEND',
					importData=data, Identify=False)

Update rows

Updates the row if the mentioned column values are matched, else a new entry will be added.

Tip : Columns is the criterian for make the MATCHING, it can be one or more values separate by coma.

objZoho.ImportRows(tableURL=Config.SERVERURL, 
                    importType='UPDATEADD',
                    importData=data,
                    Identify=False,
                    Columns='Id')

Truncateadd rows

Deletes all exisiting rows in the table and adds the imported data as new entry.

objZoho.ImportRows(tableURL=Config.SERVERURL,
                importType='TRUNCATEADD',
                importData=data)

Read Data

 

Criteria field

The criteria field is the way to make match in the table.

conditional = 'Id=1'

objZoho.readData(tableURL=Config.SERVERURL,criteria=conditional)

SQL RUN

Literal SQL Query can be used as criteria.Export using joining tables and specific columns can be done using.

sql_query = 'SELECT \"Id\",\"Name\" FROM users Where  \"Id\" = \'1\''

objZoho.readQuery(tableURL=Config.SERVERURL,queryStr=sql_query)

🍺 Buy me a beer

BTC LTC
1JDA4DEkVnB9rvLgLD5Xe9jfU2pJtnCZiG LhBrMcs7i3mD2wjiUv3KGtx9eEQeyBE4Dg