Import Data
With the Zoho Analytics API, you can add/update data in bulk. The data to be added/updated should be in CSV or JSON file formats.
REQUEST URI
https://<ZohoAnalytics_Server_URI>/api/<OwnerEmail>/<WorkspaceName>/<TableName>
Post
oauthscope: ZohoAnalytics.data.update
COMMON PARAMETERS
Parameter | Possible Values | Description |
---|---|---|
ZOHO_ACTION | IMPORT | This parameter specifies the action to be performed by the API request.Note: Value of ZOHO_ACTION parameter should be in the same case(UPPER CASE) as given in this document. |
ZOHO_OUTPUT_FORMAT | XML/JSON | This parameter specifies the output format for the response. |
ZOHO_ERROR_FORMAT | XML/JSON | Specifies the output format for the response in case an error occurs when trying to process the request. |
ZOHO_API_VERSION | 1.0 | The API version of Zoho Analytics based on which the application(/service) has been written. This parameter allows the Zoho Analytics to handle applications based on the older versions.The current API version is 1.0. |
AUTHORIZATION
To make authenticated API request, append the access token in Authorization request header.
Header Name | Value | Description |
---|---|---|
Authorization | Zoho-oauthtoken<space><access_token> | The Access token provides a secure and temporary access to Zoho Analytics API's. Each access token will be valid only for an hour, and can be used only for the set of operations that is described in the scope. |
ACTION SPECIFIC PARAMETERS
Parameter | Possible Values | Description |
---|---|---|
ZOHO_FILE or ZOHO_IMPORT_DATA (mandatory) | File or String | ZOHO_FILE - The file to be import.
ZOHO_IMPORT_DATA - The string to be import. |
ZOHO_IMPORT_FILETYPE (optional) | CSV/JSON | Default value is CSV. Format of the file to be imported. Supported formats are:
|
ZOHO_IMPORT_TYPE (mandatory) | APPEND/TRUNCATEADD/UPDATEADD |
|
ZOHO_AUTO_IDENTIFY (mandatory) | TRUE/FALSE | Used to specify whether to auto identify the CSV format. |
ZOHO_ON_IMPORT_ERROR (mandatory) | ABORT/SKIPROW/SETCOLUMNEMPTY | This parameter controls the action to be taken incase there is an error during import.
|
ZOHO_CREATE_TABLE (mandatory) | true/false. | Default is false.
|
ZOHO_SELECTED_COLUMNS (optional) | List of comma separated column names. E.g.,: Name, Department | Specify the columns to be imported into the Zoho Analytics table from the data being uploaded. Note: Incase of JSON files you need to specify the column names capturing the full JSON tree hierarchy eg., employee.Name, employee.Department |
ZOHO_MATCHING_COLUMNS (mandatory only when the ZOHO_IMPORT_TYPE is UPDATEADD) | List of comma separated column names. E.g.,: Name,Department | The values in the columns to be matched will be used for comparison to check whether data row(s) being imported matches with an existing row(s) in the table. The existing rows in the table that match will be updated with values from data imported. The remaining rows are appended to the table as new rows. |
ZOHO_SKIPTOP (optional) | <number> | Number of rows that are to be skipped from the top in the CSV file being imported. |
ZOHO_THOUSAND_SEPARATOR (optional) | 0 / 1 / 2 / 3 | Default is 0. This parameter controls the action to be taken in case there is a thousand separator in the data. 0 - COMMA 1 - DOT 2 - SPACE 3 - SINGLE QUOTE |
ZOHO_DECIMAL_SEPARATOR (optional) | 0 / 1 | Default is 0. This parameter controls the action to be taken in case there is a decimal separator in the data. 0 - DOT 1 - COMMA |
ZOHO_DATE_FORMAT (optional) | Format of the date. E.g. dd-MMM-YYYY | The format of date value. Specify this in-case any date field is being imported and its format cannot be auto recognized by Zoho Analytics. |
ZOHO_IMPORT_JSON_RETCOLNAMES (optional) | true/false. | Default value is false.
|
ZOHO_COLUMN_DATEFORMAT (optional) | JSONObject with column name as key and date format as value.E.g.,: {"columnName1":"","columnName2":""}NOTE: do encode this value and use. | Specify this in case multiple date fields are being imported having different format each. |
CSV FORMAT DETAILS
These parameters need to be specified if the ZOHO_AUTO_IDENTIFY is set to false.
Parameter | Possible Values | Description |
---|---|---|
ZOHO_COMMENTCHAR | <character> | Comment Character. If the character mentioned is found at the beginning of the row, the csv row will be skipped. |
ZOHO_DELIMITER | 0 / 1 / 2 / 3 | Delimiter which separates the values in the file. 0 - if the delimiter is COMMA 1 - if the delimiter is TAB 2 - if the delimiter is SEMICOLON 3 - if the delimiter is SPACE |
ZOHO_QUOTED | 0 / 1 / 2 | The Text Qualifier. 0 - None 1 - SINGLE QUOTE 2 - DOUBLE QUOTE |
POSSIBLE ERROR CODES
7103 , 7138 , 7235 , 8002 , 8004 , 8504 , 8506 , 8516 , 8533
Sample Request:
Copiedcurl -X POST 'https://analyticsapi.zoho.com/api/UserEmail/WorkspacName/TableName?
ZOHO_ACTION=IMPORT&ZOHO_OUTPUT_FORMAT=XML&ZOHO_ERROR_FORMAT=XML&
ZOHO_API_VERSION=1.0&ZOHO_IMPORT_TYPE=APPEND&
ZOHO_AUTO_IDENTIFY=TRUE&ZOHO_ON_IMPORT_ERROR=ABORT&ZOHO_CREATE_TABLE=true'
-H 'content-type: multipart/form-data'
-H 'Authorization:Zoho-oauthtoken <access_token>'
-F 'ZOHO_FILE=@/home/local/import.csv'
Copiedusing ZReports;
namespace Test
{
class Program
{
public IReportClient GetClient()
{
IReportClient RepClient = new ReportClient(CLIENT_ID, CLIENT_SECRET, REFRESH_TOKEN);
return RepClient;
}
public void ImportData(IReportClient RepClient)
{
string tableURI = RepClient.GetURI(EMAIL, DBNAME, TBNAME);
Dictionary<string, string> ImportConfig = new Dictionary<string, string>();
ImportConfig.Add("ZOHO_ON_IMPORT_ERROR", "ABORT");
ImportConfig.Add("ZOHO_CREATE_TABLE", "TRUE");
ImportConfig.Add("ZOHO_AUTO_IDENTIFY", "TRUE");
Dictionary<string, string> ImportRes = RepClient.ImportData(tableURI, ZohoReportsConstants.APPEND, "C:\\workspace\\mydata.csv", ImportConfig);
}
static void Main(string[] args)
{
Program obj = new Program();
IReportClient rc = obj.GetClient();
obj.ImportData(rc);
}
}
}
Copiedpackage main
import (
"fmt"
"zoho/pkg/reportclient"
)
var (
email = "Email Address"
dbname = "Workspace Name"
tbname = "Table Name"
clientid = "************"
clientsecret = "************"
refreshtoken = "************"
)
func importdata() {
url := reportclient.GetUri(email, dbname, tbname)
params := map[string]string{}
file := "/home/sample.csv"
importtype := "APPEND"
autoidentity := "true"
onerror := "ABORT"
resp, err := reportclient.ImportData(url, file, importtype, autoidentity, onerror, params)
if err != nil {
fmt.Println(err.ErrorMessage)
fmt.Println(err.ErrorCode)
fmt.Println(err.Action)
fmt.Println(err.HttpStatusCode)
} else {
fmt.Println(resp.ImportErrors)
fmt.Println(resp.ColumnDetails)
fmt.Println(resp.ImportType)
fmt.Println(resp.Warnings)
fmt.Println(resp.SelectedColumnCount)
fmt.Println(resp.SuccessRowCount)
fmt.Println(resp.ImportOperation)
fmt.Println(resp.TotalColumnCount)
fmt.Println(resp.TotalRowCount)
}
}
func main() {
reportclient.SetOAuthToken(clientid, clientsecret, refreshtoken)
importdata()
}
Copiedimport com.adventnet.zoho.client.report.*;
public class Sample {
String email = "Email Address";
String dbname = "Workspace Name";
String tbname = "Table Name";
String clientId = "************";
String clientSecret = "************";
String refreshToken = "************";
Map<String, Object> config = new HashMap<>();
File csvFile = new File("samples/StoreSales.csv");
private ReportClient rc = new ReportClient(clientId, clientSecret, refreshToken);
public void importdata() throws Exception {
String uri = rc.getURI(email, dbname, tbname);
config.put("ZOHO_AUTO_IDENTIFY", "true");
config.put("ZOHO_ON_IMPORT_ERROR", "ABORT");
config.put("ZOHO_CREATE_TABLE", "false");
Object result = rc.importData(uri, "APPEND", csvFile, config, false);
}
public static void main(String[] args) throws Exception {
Sample obj = new Sample();
obj.importdata();
}
}
Copied<?php
require 'ReportClient.php';
$EMAIL_ID = "Email Address";
$DB_NAME = "Workspace Name";
$TABLE_NAME = "Table Name";
$CLIENT_ID = "************";
$CLIENT_SECRET = "************";
$REFRESH_TOKEN = "************";
$report_client_request = new ReportClient($CLIENT_ID, $CLIENT_SECRET, $REFRESH_TOKEN);
$uri = $report_client_request->getURI($EMAIL_ID, $DB_NAME, $TABLE_NAME);
$import_type = "APPEND";
$file = "complete file path"; // E.g: "/home/local/user/Sample.csv"
$auto_identify = "TRUE";
$on_error = "ABORT";
$response_obj = $report_client_request->importData($uri, $import_type, $file, $auto_identify, $on_error);
?>
Copiedfrom __future__ import with_statement
from ReportClient import ReportClient
import sys
class Sample:
LOGINEMAILID = "abc@zoho.com"
CLIENTID = "************"
CLIENTSECRET = "************"
REFRESHTOKEN = "************"
rc = None
rc = ReportClient(REFRESHTOKEN, CLIENTID, CLIENTSECRET)
def importData(self, rc):
uri = rc.getURI(self.LOGINEMAILID, self.DATABASENAME, self.TABLENAME)
try:
with open('StoreSales.csv', 'r') as f:
importContent = f.read()
autoIdentify = "true"
onError = "ABORT"
except Exception as e:
print("Error Check if file StoreSales.csv exists in the current directory")
print("(" + str(e) + ")")
return
impResult = rc.importData(uri, "APPEND", importContent, autoIdentify, onError, None)
print("Added Rows: " + str(impResult.successRowCount) + " and Columns: " + str(impResult.selectedColCount))
obj = Sample()
obj.importData(obj.rc)
Copiedvar nodelib = require('./ZAnalyticsClient');
var clientId = '************';
var clientSecret = '************';
var refreshToken = '************';
var emailId = 'EmailAddress';
var workspaceName = 'WorkspaceName';
var viewName = 'ViewName';
nodelib.initialize(clientId, clientSecret, refreshToken).then(() => {
var filepath = '';
var params = {};
params['ZOHO_IMPORT_FILETYPE'] = 'JSON';
var importType = 'APPEND';
var autoIdentify = true;
var onImportError = 'ABORT';
var uripath = nodelib.getUri(emailId, workspaceName, viewName);
nodelib.importData(filepath, importType, autoIdentify, onImportError, uripath, params).then((response) => {
console.log(response);
}).catch((error) => {
console.log('Error: ' + error.message);
});
}).catch((error) => {
console.log('Authentication Error: ' + error);
});
Copiedemail = zoho.encryption.urlEncode("");
workspaceName = zoho.encryption.urlEncode("");
viewName = zoho.encryption.urlEncode("");
paramsMap = Map();
oauthParams = Map();
headers = Map();
// AUTHENTICATION PARAMS
oauthParams.put("client_id", "********");
oauthParams.put("client_secret", "********");
oauthParams.put("refresh_token", "********");
oauthParams.put("grant_type", "refresh_token");
tokenInfo = invokeurl[url: "https://accounts.zoho.com/oauth/v2/token" type: POST parameters: oauthParams];
if (tokenInfo.containKey("access_token")) {
accessToken = tokenInfo.get("access_token");
headers.put("Authorization", "Zoho-oauthtoken ".concat(accessToken));
} else {
info tokenInfo;
return;
}
file = invokeurl[url: "" // download link of the file to be imported type: GET
];
// COMMON PARAMS
paramsMap.put("ZOHO_ACTION", "IMPORT");
paramsMap.put("ZOHO_OUTPUT_FORMAT", "JSON");
paramsMap.put("ZOHO_ERROR_FORMAT", "JSON");
paramsMap.put("ZOHO_API_VERSION", "1.0");
// ACTION SPECIFIC PARAMS
paramsMap.put("ZOHO_IMPORT_TYPE", "");
paramsMap.put("ZOHO_AUTO_IDENTIFY", "");
paramsMap.put("ZOHO_ON_IMPORT_ERROR", "");
paramsMap.put("ZOHO_CREATE_TABLE", "");
queryParam = "";
keyList = paramsMap.keys();
foreach key in keyList {
queryParam = queryParam + "&" + key + "=" + paramsMap.get(key);
}
response = invokeurl[url: "https://analyticsapi.zoho.com/api/" + email + "/" + workspaceName + "/" + viewName + "?" + queryParam type: POST files: { "paramName": "ZOHO_FILE", "content": file } headers: headers];
info response;