C# Library
The C# client libraries wraps the raw HTTP based API of Zoho Reports with easy to use methods for the C# .Net platform. This enables C# .Net developers to easily use Zoho Reports API.Prerequisites:
It is recommend to go through the Zoho Reports API Documentation and the Prerequisites before using the C# client library code in your application.
Download C# Client Library:
Download the C# client library (dll) from the following links.
- ZohoReports.dll (32-bit)
- ZohoReports.dll (64-bit)
Add reference to your C# Projects using these .dll files. With this you will be able to perform Zoho Reports API operations using the available functions.
API Reference Documentation:
All the available APIs in the C# Client Library can be referred in the C# API Reference Documentation.
Methods Summary:
C# .Net developers need to create a ReportClient object to access the below functions. The sample code snippet is below.
The ReportClient constructor has a single argument called AuthToken. You can find more information on how to get a AuthToken here. Once the ReportClient object is created, you can invoke the below methods from your C# .Net programming language.
GetURI
public string GetURI(string userEmailId)
This function returns the URI for performing User Management API requests/operations
Parameters:
- string userEmailId - The Primary Email Address of your Zoho Reports Account
Returns:
The URI for performing user specific API operations.
public string GetURI(string AdminEmailId, string DatabaseName)
This function returns the URI for performing Zoho Reports Database specific API operations.
Parameters:
- string AdminEmailId - The Primary Email Address of your Zoho Reports Account.
- string DatabaseName - The Zoho Reports Database Name
Returns:
The URI for performing Zoho Reports Database specific API operations.
public string GetURI(string AdminEmailId, string DatabaseName, string ViewName)
This function returns the URI for performing Zoho Reports View specific API operations.
Parameters:
- string AdminEmailId - The Primary Email Address of your Zoho Reports Account.
- string DatabaseName - The Zoho Reports Database Name
- string ViewName - The Zoho Reports View Name. This could be a chart, pivot table, summary view, table, query table or dashboard created in Zoho Reports.
Returns:
The URI for performing Zoho Reports View specific API operations
Import Data
public Dictionary<string,string> ImportData(string TableURI, string ImportType, string CSVFilePath, Dictionary<string, string> ImportConfig)
This function is used to Import data from a local CSV/TSV/Txt file into Zoho Reports Online Reporting Database Table. This function is referring to Zoho Reports Import API.
Parameters:
- string TableURI - The URI of the Table, into which the data has to be imported, got from the GetURI function
- string ImportType - The Import Type for the import process. This can be taken from ZohoReportsConstants file (which has all the constant variables used in this Library).
- string CSVFilePath - The file path of your data file.
- Dictionary ImportConfig - This parameter holds the import parameters such as ZOHO_ON_IMPORT_ERROR, ZOHO_DATE_FORMAT, etc. You can check out the list of import parameters here.
Returns:
The import summary with summary name as Key and summary value as Value
Add Row
public Dictionary <string,string> AddRow (string TableURI, Dictionary<string,string> ColumnValues, Dictionary<string,string> Config)
This function is used to Add a row to a Zoho Reports Table. The row data present in the ColumnValues Dictionary will be added as a row in the specified Zoho Reports Table. This function uses the HTTP Zoho Reports Add Row API.
Parameters:
- string TableURI - The URI of the table, into which the data is to be added, got from the GetURI function.
- Dictionary ColumnValues - The Dictionary of Column Names and Values. The Values are added to the respective columns specified in the columnValues Dictionary.
- Dictionary Config - The Dictionary for sending extra parameters, if any.
Returns:
Added values with column name as Key and row value as Value
Update Data
public void UpdateData (string TableURI, Dictionary<string, string> ColumnValues, string Criteria, Dictionary<string, string> Config)
This function is used to Update Rows in a Zoho Reports Table which matches the specified criteria. If the criteria provided is null, then all the rows will be updated with the new values provided in ColumnValues Dictionary. This function uses the HTTP Zoho Reports Update Data API.
Parameters:
- string TableURI - The URI of the table, in which the data is to be updated, got from the GetURI function
- Dictionary ColumnValues - The Dictionary of Column Names and Values. The Values are updated to the respective columns specified in the columnValues Dictionary.
- string Criteria - Criteria for updating rows. The rows matching the specified criteria alone will get updated. The criteria follows the SQL SELECT WHERE condition like format. More details on specifying Zoho Criteria is available in Applying Filters section.
- Dictionary Config - The Dictionary for sending extra parameters, if any.
Delete Data
public void DeleteData (string TableURI, string Criteria, Dictionary<string, string> Config)
This function is used to Delete the Rows in a Zoho Reports Table which matches the specified criteria. If the criteria provided isnull, then all the rows will be deleted. This function uses the HTTP Zoho Reports Delete Data API.
Parameters:
- string TableURI - The URI of the table, in which the data is to be deleted, got from the GetURI function
- string Criteria - Criteria for deleting rows. The rows matching the specified criteria alone will get deleted. The criteria follows the SQL SELECT WHERE condition like format. More details on specifying Zoho Criteria is available in Applying Filters section.
- Dictionary Config - The Dictionary for sending extra parameters, if any.
Export Data As JSON
public string ExportDataAsJSON (string ViewURI, string Criteria, Dictionary<string, string> Config)
This function is used to Export the data from a Zoho Reports Table / Report in a JSON format. This function uses the HTTP Zoho Reports Export API.
Parameters:
- string ViewURI - The URI of the view, from which the data is to be exported, got from the GetURI function
- string Criteria - Criteria for exporting data. The rows matching the specified criteria alone will get exported. The criteria follows the SQL SELECT WHERE condition like format. More details on specifying Zoho Criteria is available in Applying Filters section.
- Dictionary Config - The Dictionary for sending extra parameters, if any.
Returns:
The JSON string which contains the exported data.
Export Data As CSV
public string ExportDataAsCSV (string ViewURI, string Criteria, Dictionary<string, string> Config)
This function is used to Export the data from a Zoho Reports Table / Report in a CSV format. This function uses the HTTP Zoho Reports Export API.
Parameters:
- string ViewURI - The URI of the view, from which the data is to be exported, got from the GetURI function
- string Criteria - Criteria for exporting data. The rows matching the specified criteria alone will get exported. The criteria follows the SQL SELECT WHERE condition like format. More details on specifying Zoho Criteria is available in Applying Filters section.
- Dictionary Config - The Dictionary for sending extra parameters, if any.
Returns:
The CSV string which contains the exported data.
Export Data As File
public void ExportData (string ViewURI, string Format, String OutputFileName, string Criteria, Dictionary<string, string> Config)
This function is used to export the Zoho Reports Table / Report / Dashboard data in the name of the specified file. This function uses the HTTP Zoho Reports Export API.
Parameters:
- string ViewURI - The URI of the view, from which the data is to be exported, got from the GetURI function
- string Format - The output format for exporting the data. The supported formats are CSV, XML, JSON, HTML, PDF, IMAGE.
- string OutputFileName - The data will be exported to the specified output file in the local machine.
- string Criteria - Criteria for exporting data. The rows matching the specified criteria alone will get exported. The criteria follows the SQL SELECT WHERE condition like format. More details on specifying Zoho Criteria is available in Applying Filters section.
- Dictionary Config - The Dictionary for sending extra parameters, if any.
- string ViewURI - The URI of the view, from which the data is to be exported, got from the GetURI function
- string Format - The output format for exporting the data. The supported formats are CSV, XML, JSON, HTML, PDF, IMAGE.
- Stream OutputStream - The output stream to which the data has to be exported.
- string Criteria - Criteria for exporting data. The rows matching the specified criteria alone will get exported. The criteria follows the SQL SELECT WHERE condition like format. More details on specifying Zoho Criteria is available in Applying Filterssection.
- Dictionary Config - The Dictionary for sending extra parameters, if any.
- string ViewURI - The URI of the view, from which the data is to be exported, got from the GetURI function
- string Criteria - Criteria for exporting data. The rows matching the specified criteria alone will get exported. The criteria follows the SQL SELECT WHERE condition like format. More details on specifying Zoho Criteria is available in Applying Filters section.
- Dictionary Config - The Dictionary for sending extra parameters, if any.
- string ViewURI - The URI of the view, from which the data is to be exported, got from the GetURI function
- string Format - The output format for exporting the data. The supported formats are CSV, XML, JSON, HTML, PDF, IMAGE.
- string OutputFileName - The data will be exported to the specified output file in the local machine
- string SQLQuery - The SQL SELECT Query which has to be executed to fetch the result set that is to be executed
- Dictionary Config - The Dictionary for sending extra parameters, if any.
- string ViewURI - The URI of the view, from which the data is to be exported, got from the GetURI function
- string Format - The output format for exporting the data. The supported formats are CSV, XML, JSON, HTML, PDF, IMAGE.
- Stream OutputStream - The output stream to which the data has to be exported.
- string SQLQuery - The SQL SELECT Query which has to be executed to fetch the result set that is to be executed
- Dictionary Config - The Dictionary for sending extra parameters, if any.
- string DatabaseURI - The corresponding Zoho Reports Database URI got from the GetURI function
- string MetaData - The metadata type which can be got from ZohoReportsConstants file.
- string format - The response format for the metadata. The supported formats are XML and JSON.
- Dictionary Config - The Dictionary for sending extra parameters, if any.
- string DatabaseURI - The corresponding Zoho Reports Database URI got from the GetURI function
- Dictionary Config - The Dictionary for sending extra parameters, if any.
- string DatabaseURI - The URI of the Zoho Reports Database to be copied, got from the GetURI function.
- string NewDBName - The Database Name for the newly copied database
- string NewDBDescription - The Description for the newly copied database
- bool WithData - If true, the database will be copied along with data, else the database will be copied without data
- Dictionary Config - The Dictionary for sending extra parameters, if any.
- string AccountURI - Your Zoho Reports Account URI got from the GetURI function
- string DatabaseName - The name of the database to be deleted
- string AccountURI - Your Zoho Reports AccountURI got from GetURI function.
- string EmailIds - The Zoho primary email addresses of the users to be added, separated by comma (,).
- Dictionary Config - The Dictionary for sending extra parameters, if any.
- string AccountURI - Your Zoho Reports AccountURI got from GetURI function.
- string EmailIds - The Zoho primary email addresses of the users to be removed, separated by comma (,).
- Dictionary Config - The Dictionary for sending extra parameters, if any.
- string AccountURI - Your Zoho Reports AccountURI got from GetURI function
- string EmailIds - The Zoho primary email addresses of the users to be activated, separated by comma (,)
- Dictionary Config - The Dictionary for sending extra parameters, if any.
- string AccountURI - Your Zoho Reports AccountURI got from GetURI function.
- string EmailIds - The Zoho primary email addresses of the users to be de-activated, separated by comma (,)
- Dictionary Config - The Dictionary for sending extra parameters, if any.
- string host - The host name or IP Address of your proxy host
- int port - The port number for connecting your proxy
- string user - The username for authenticating to your proxy
- string password - The password for authenticating to your proxy
- ZOHO_CATALOG_LIST - To list the Zoho Reports databases for the specified user
- ZOHO_CATALAOG_INFO - To fetch information about the tables & reports (view) present in the given reporting database in Zoho Reports.
- ZOHO_DATATYPES - To get the list of datatypes supported by Zoho Reports
- ZOHO_TABLETYPES - Various view types available in Zoho Reports
- APPEND - Appends the data into the table.
- TRUNCATEADD - Deletes all existing rows in the table and adds the imported data as a new entry.
- UPDATEADD - Updates the row if the mentioned column values (in ZOHO_MATCHING_COLUMNS parameter) are matched, else a new entry will be added.
- Creating ReportClient object
- Import API
- Add Row API
- Update Row API
- Delete Row API
- Export API
- Calling API functions from Main function
Export Data As Stream
public void ExportData (string ViewURI, string Format, Stream outputStream, string Criteria, Dictionary<string, string> Config)
This function is used to export the Zoho Reports Table / Report / Dashboard data in the specified Output Stream. This function uses the HTTP Zoho Reports Export API.
Parameters:
Export Data As Dictionary
public Dictionary<string,object> ExportDataAsDictionary (string ViewURI, string Criteria, Dictionary<string, string> Config).
This function is used to export the Zoho Reports Table / Report data as C# Dictionary object. You can then parse this object to retrieve the resultant data. This function uses the HTTP Zoho Reports Export API.
Parameters:
Returns:
It returns Dictionary<string,object> containing the data. You can iterate this object to get the result. The sample resultant Dictionary will be as below.
Key<string>: column_order
Value<Object[]>: ["column1","column2",..,"columnN"]
Key<string>: rows
Value<Object[]>: [ [value11,value12,..,value1N],[value21,valuu22,..,value2N] ]
Export Data Using SQL As File
public void ExportDataUsingSQL (string ViewURI, string Format, String OutputFileName, string SQLQuery, Dictionary<string, string> Config)
This function is used to export the Table data got by executing the given SQL SELECT Query in your Zoho Reports database. This function uses the HTTP Zoho Reports Cloud SQL API Specification.
Parameters:
Export Data Using SQL As Stream
public void ExportDataUsingSQL (string ViewURI, string Format, Stream outputStream, string SQLQuery, Dictionary<string, string> Config)
This function is used to export the Table data got by executing the given SQL SELECT Query in your Zoho Reports database. The data will exported into the specified output stream. This function uses the Zoho Reports Cloud SQL API Specification.
Parameters:
Meta Data
public string GetDatabaseMetaData (string DatabaseURI, string MetaData, string format, Dictionary<string, string> Config)
This function is used to get the Zoho Reports Database Metadata in the specified format (XML / JSON). You can then parse this XML / JSON to retrieve the resultant data.
Parameters:
Returns:
The meta data will be returned as an XML / JSON (based on the specified format) which you can parse to get the meta data.
Get Copy DB Key
public string GetCopyDBKey (string DatabaseURI, Dictionary<string, string> Config)
This function is used to get the Copy Database Key. This key will be required in CopyDatabase function for copying the database.
Parameters:
Returns:
The Copy Database Key for the specified database in the DatabaseURI
Copy Database
public long CopyDatabase (string DatabaseURI, string NewDBName, string NewDBDescription, bool WithData, string CopyDBKey, Dictionary<string,string> Config)
This function is used to copy the database in your Zoho Reports Account. The database will be copied, if the CopyDBKey is valid.
Parameters:
Returns:
The Database ID for the newly copied database.
Delete Database
public void DeleteDatabase(string AccountURI, string DatabaseName, Dictionary<string, string> Config)
This function is used to delete a database from your Zoho Reports Account.
Parameters:
Add User
public void AddUser(string AccountURI, string EmailIds, Dictionary<string, string> Config)
This function is used to Add one or more users to your Zoho Reports Account. The added users will be associated to the Administrator's Zoho Reports Account. This function does not Sign Up the user in Zoho, if the added user does not exists in Zoho. By default all the new users added will be set to Active state, and will be counted into Zoho Reports account user limit.
Parameters:
Remove User
public void Remove User(string AccountURI, string EmailIds, Dictionary<string, string> Config)
This function is used to Remove one or more users from your Zoho Reports Account. This action does not remove the user from Zoho, just removes the association of that user in your Zoho Reports account.
Parameters:
Activate User
public void Activate User(string AccountURI, string EmailIds, Dictionary<string, string> Config)
This function is used to Activate one or more users in your Zoho Reports Account.
Parameters:
De-Activate User
public void DeActivate User(string AccountURI, string EmailIds, Dictionary<string, string> Config)
This function is used to Deactivate one or more users in your Zoho Reports Account.
Parameters:
Set Web Proxy
public void SetWebProxy(string host, int port, string user, string password).
This function is used to set the proxy details if your network uses proxy.
Parameters:
ZohoReportsConstants:
This C# client library has a sealed class called ZohoReportsConstants. This class has the list of constants used in this library. The available constants are below.
Constants used in GetDatabaseMetaData function:
Constants used in ImportData function:
Sample Program:
The below sample program illustrates how to invoke Zoho Reports API using Zoho Reports C# client library.
The program steps are classified as follow.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using ZReports; // Namespace which contains classes for invoking Zoho Reports APIs namespace MyZohoReportsClient { class MyJob { /* Creating ReportClient object for invoking Zoho Reports APIs */ public IReportClient getClient() { // Creating ReportClient Object using Auth Token // ReportClient class contains all the supported API operations as functions IReportClient RepClient = new ReportClient("---your_authtoken_here---"); return RepClient; } /* The following method uses Zoho Reports IMPORT API to import the data from a local file into Zoho Reports Table. This method illustrates importing data from the location "C:\workspace\mydata.csv" into the table named "MyTable1" in "MyDB" reporting database. The usage of Import API is described below. IMPORT API: The IMPORT API allows you to import the data from your local file into Zoho Reports Table. Zoho Reports C# Library Function: ImportData(string tableURI, string ImportType, string FilePath, Dictionary<string,string> ImportConfig) Parameters: string tableURI This is the URI for the Zoho Reports Table into which the data has to be imported. Get the tableURI from GetURI(emailId,databaseName,tableName) function. The GetURI function will get your email address, the Zoho Reports Database Name and Zoho Reports Table Name as parameters. string ImportType This specifies how to import data. The Import type parameter can be set to APPEND, TRUNCATEADD or UPDATEADD. These constants can be set from ZohoReportsConstants class To know more about the Import Types, refer the Zoho Reports Import API Parameters section. string FilePath The location of the file which needs to be imported into Zoho Reports. The Import API will read the data from the file specified in this parameter and uploads the same into Zoho Reports Table. Dictionary<string,string> ImportConfig Dictionary to specify the additional Import Parameters. This Dictionary has the Parameter Name as Key and Parameter Value as Value. This ImportData function returns the Import Summary as a Dictionary */ public void importData(IReportClient RepClient) { string tableURI = RepClient.GetURI("testuser@zoho.com", "MyDB", "MyTable1"); Dictionary<string, string> ImportConfig = new Dictionary<string, string>(); ImportConfig.Add("ZOHO_ON_IMPORT_ERROR", "ABORT"); Dictionary<string, string> ImportRes = RepClient.ImportData(tableURI, ZohoReportsConstants.APPEND, "C:\\workspace\\mydata.csv",ImportConfig); } /* The following method uses Zoho Reports ADDROW API to add a single row into the Zoho Reports Table. This method illustrates adding a single row to the table "MyTable1" in "MyDB" database. This table consists of a single column named "Region" The usage of AddRow API is described below. ADDROW API: The ADDROW API allows you to add a single row into the specified Zoho Reports table. Zoho Reports C# Library Function: AddRow(string tableURI,Dictionary<string,string> ColumnValues,Dictionary<string,string> Config) Parameters: string tableURI This is the URI for the Zoho Reports Table into which the data has to be imported. Get the tableURI from GetURI(emailId,databaseName,tableName) function. The GetURI function will get your email address, the Zoho Reports Database Name and Zoho Reports Table Name as parameters. Dictionary<string,string> ColumnValues The Dictionary which has Zoho Reports Table Column Name as Key and Column Value as Value. All the entries in the ColumnValues Dictionary will be added as a Row in the specified table in the tableURI Dictionary<string,string> Config Useful for sending additional parameters, if any. This Dictionary has the Parameter Name as Key and Parameter Value as Value. This AddRow function returns the added values as a Column Name vs. Column Value Dictionary */ public void addRow(IReportClient RepClient) { string tableURI = RepClient.GetURI("testuser@zoho.com", "MyDB", "MyTable1"); Dictionary<string, string> ColumnValues = new Dictionary<string, string>(); ColumnValues.Add("Region", "South"); Dictionary<string, string> addRowRes = RepClient.AddRow(tableURI, ColumnValues, config); } /* The following method uses Zoho Reports UPDATE API to update rows in Zoho Reports Table. This method illustrates updating the value 'South' with 'North' for the column "Region" in the Zoho Reports table "MyTable1" in "MyDB" database. The usage of UpdateData API is described below. UPDATE API: The data present in a Zoho Reports Table can be updated using Zoho Reports UPDATE API. Zoho Reports C# Library Function: UpdateData(string tableURI, Dictionary<string,string> ColumnValues, string criteria, Dictionary<string,string> Config) Parameters: string tableURI This is the URI for the Zoho Reports Table into which the data has to be updated. Get the tableURI from GetURI(emailId,databaseName,tableName) function. The GetURI function will get your email address, the Zoho Reports Database Name and Zoho Reports Table Name as parameters. Dictionary<string,string> ColumnValues The Dictionary which has Zoho Reports Table Column Name as Key and Column Value as Value. All the entries in the ColumnValues Dictionary will be updated in the specified table in the tableURI string criteria Criteria for updating data. The rows matching this criteria alone will get updated. The criteria should follow the same format as that of the SQL WHERE clause. To know more about specifying criteria, refer the Applying Filters section in Zoho Reports API Documentation. Dictionary<string,string> Config Useful for sending additional parameters, if any. This Dictionary has the Parameter Name as Key and Parameter Value as Value. This UpdateData function will not return any object. */ public void updateRow(IReportClient RepClient) { string tableURI = RepClient.GetURI("testuser@zoho.com", "MyDB", "MyTable1"); Dictionary<string, string> ColumnValues = new Dictionary<string, string>(); ColumnValues.Add("Region", "North"); string criteria = "\"Region\"='South'"; RepClient.UpdateData(tableURI, ColumnValues, criteria, null); } /* The below method uses Zoho Reports DELETE API to delete rows in Zoho Reports Table. In this method, the rows matching value 'South' in column Region is deleted from the table MyTable1 in MyDB database. The usage of DeleteData API is described below. DELETE API: The data present in a Zoho Reports Table can be deleted using Zoho Reports DELETE API. Zoho Reports C# Library Function: DeleteData(string tableURI, string criteria, Dictionary<string,string> Config) Parameters: string tableURI This is the URI for the Zoho Reports Table into which the data has to be deleted. Get the tableURI from GetURI(emailId,databaseName,tableName) function. The GetURI function will get your email address, the Zoho Reports Database Name and Zoho Reports Table Name as parameters. string criteria Criteria for deleting data. The rows matching this criteria alone will get deleted. The criteria should follow the same format as that of the SQL WHERE clause. To know more about specifying criteria, refer to the Applying Filters section in Zoho Reports API Documentation. Dictionary<string,string> Config Useful for sending additional parameters, if any. This Dictionary has the Parameter Name as Key and Parameter Value as Value. This DeleteData function will not return any object. */ public void deleteRow(IReportClient RepClient) { string tableURI = RepClient.GetURI("testuser@zoho.com", "MyDB", "MyTable1"); string criteria = "\"Region\"='South'"; RepClient.DeleteData(tableURI, criteria, null); } /* The following method uses Zoho Reports EXPORT API to Export data from a Zoho Reports Table or Report. This method illustrates exporting the data matching value 'West' in column "Region" from the Zoho Reports Table "MyTable1" in "MyDB" database. The usage of Export API is described below. EXPORT API: The data present in a Zoho Reports Table or Report can be exported using Zoho Reports EXPORT API. Zoho Reports C# Library Function: ExportDataAsObject(string tableOrReportURI, string criteria, Dictionary<string,string> Config) Parameters: string tableOrReportURI This is the URI for the Zoho Reports Table or Report from which the data has to be exported. Get the tableOrReportURI from GetURI(emailId,databaseName,tableNameOrReportName) function. The GetURI function will get your email address, the Zoho Reports Database Name and Zoho Reports Table Name as parameters. string criteria Criteria for exporting data. The rows matching this criteria alone will get exported. The criteria should follow the same format as that of the SQL WHERE clause. To know more about specifying criteria, refer to the Applying Filters section in Zoho Reports API Documentation. Dictionary<string,string> Config Useful for sending additional parameters, if any. This Dictionary has the Parameter Name as Key and Parameter Value as Value. This ExportDataAsObject function will return an object which can be iterated to get the result. */ public object export(IReportClient RepClient) { string tableURI = RepClient.GetURI("testuser@zoho.com", "MyDB", "MyTable1"); Dictionary<string, object> resObj = RepClient.ExportDataAsDictionary(tableURI, "\"Region\"='West'", null);
Object[] columns = (Object[])resObj["column_order"];
Object[] rows = (Object[])resObj["rows"];
} public static void Main(string[] s) { MyJob myJob = new MyJob(); IReportClient rc = myJob.getClient(); myJob.importData(rc); myJob.addRow(rc); myJob.updateRow(rc); myJob.deleteRow(rc); myJob.export(rc); Console.Read(); } } }