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

ParameterPossible ValuesDescription
ZOHO_ACTIONIMPORTThis 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_FORMATXML/JSONThis parameter specifies the output format for the response.
ZOHO_ERROR_FORMATXML/JSONSpecifies the output format for the response in case an error occurs when trying to process the request.
ZOHO_API_VERSION1.0The 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 NameValueDescription
AuthorizationZoho-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

ParameterPossible ValuesDescription
ZOHO_FILE or 
ZOHO_IMPORT_DATA
(mandatory)
File or String

ZOHO_FILE - The file to be import.

  • In the case of importing files multipart/form-data format should be used. (This is the default format used by html forms that contain file type fields used for uploading files)
  • Maximum allowed file size is 100 MB.

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:

  • CSV
  • JSON
ZOHO_IMPORT_TYPE
(mandatory)
APPEND/TRUNCATEADD/UPDATEADD
  • 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.
ZOHO_AUTO_IDENTIFY
(mandatory)
TRUE/FALSEUsed 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.

  • ABORT - Incase of any error, abort the whole import.
  • SKIPROW - In case of any error, skip that specific row(s) which has the problem and continue importing the rest.
  • SETCOLUMNEMPTY - In case of any error, set the value of the error column for the row to empty and continue importing.
ZOHO_CREATE_TABLE
(mandatory)
true/false.

Default is false.

  • In case it is true, then the table is created if the table referred in the URL doesn’t exists in the specified Workspace.
  • In case its false, no table is created even if the table referred in the URL does not exists in the Workspace.
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 / 3Default 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 / 1Default 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.
This parameter is applicable only for importing JSON files. This defines how the columns names are to be constructed from the JSON file.

  • If set to true, then the final key attribute alone will be considered as column name.
  • If set to false, then the column name will be constructed by appending all the parent attributes separated by dot (.). This will result in column names which captures the full JSON tree hierarchy Eg., employee.Name, employee.Department
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.

ParameterPossible ValuesDescription
ZOHO_COMMENTCHAR<character>Comment Character. If the character mentioned is found at the beginning of the row, the csv row will be skipped.
ZOHO_DELIMITER0 / 1 / 2 / 3Delimiter 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_QUOTED0 / 1 / 2The 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;

Download SDK:C# | GO | JAVA | PHP | PYTHON | NodeJS