Create Import Job for an existing table
You can create an import job to import data into a specified table.
REQUEST URI
https://<ZohoAnalytics_Server_URI>restapi/v2/bulk/workspaces/<workspace-id>/views/<view-id>/data
Post
oauthscope: ZohoAnalytics.data.create
ACTION SPECIFIC PARAMETERS
| Description |
---|---|
FILE* | File
|
QUERY PARAMETERS
| Description |
---|---|
CONFIG* | JSONObject Config parameter specifications are available in the below section. |
FIELDS FOR CONFIG JSON
Key | Description |
---|---|
importType* | String
|
fileType* | String
|
autoIdentify* | Boolean
|
onError | String
|
matchingColumns (mandatory only when the importType is updateadd) | JSONArray
|
selectedColumns | JSONArray
|
skipTop | Integer
|
thousandSeparator | Integer
|
decimalSeparator | Integer
|
dateFormat | String
|
columnDateFormat | JSONObject
|
callbackUrl | String
|
columnDataTypes | JSONArray
Supported data types:
|
CSV SPECIFIC ATTRIBUTES
Note: These attributes are mandatory if autoIdentify is set to false.
Key | Description |
---|---|
commentChar | Char If the character mentioned is found at the beginning of the row, the csv row will be skipped. Sample: # |
delimiter | Integer
|
quoted | Integer
|
JSON SPECIFIC ATTRIBUTES
Note: These attributes are mandatory if autoIdentify is set to false.
Key | Description |
---|---|
retainColumnNames | Boolean
|
POSSIBLE ERROR CODES
7103, 7111, 7138, 7232, 7248, 7249, 8046, 8119, 8504, 8506, 8513, 8516
Sample Request
Copiedcurl https://analyticsapi.zoho.com/restapi/v2/bulk/workspaces/<workspace-id>/views/<view-id>/data?CONFIG=<encoded_json_value>
-F 'FILE=@/home/local/import.csv'
-X 'POST'
-H 'ZANALYTICS-ORGID: <org-id>'
-H 'Authorization: Zoho-oauthtoken <access_token>'
Copiedusing System;
using System.Collections.Generic;
using ZohoAnalytics;
using System.Text.Json;
namespace ZohoAnalyticsTest
{
class Program
{
long orgId = 55522777;
long workspaceId = 35130000001055707;
long viewId = 35730000007354002;
public void ImportBulkData(IAnalyticsClient ac)
{
string importType = "append";
string fileType = "json";
bool autoIdentify = true;
string filePath = "D:\\sales_v2.json";
IBulkAPI data = ac.GetBulkInstance(orgId, workspaceId);
long jobId = data.ImportBulkData(viewId, importType, fileType, autoIdentify, filePath, null);
Console.WriteLine(jobId);
}
static void Main(string[] args)
{
string clientId = "1000.xxxxxxx";
string clientSecret = "xxxxxxx";
string refreshToken = "1000.xxxxxxx.xxxxxxx";
try
{
IAnalyticsClient ac = new AnalyticsClient(clientId, clientSecret, refreshToken);
Program obj = new Program();
obj.ImportBulkData(ac);
}
catch (ServerException ex)
{
Console.WriteLine("Server exception - " + ex.GetErrorMessage());
}
catch (Exception ex)
{
Console.WriteLine("Other exception - " + ex.Message);
}
}
}
}
Copiedpackage main
import (
"fmt"
ZAnalytics "zoho/pkg/analyticsclient"
)
var(
clientId = "1000.xxxxxxx"
clientSecret = "xxxxxxx"
refreshToken = "1000.xxxxxxx.xxxxxxx"
orgId = "55522777"
workspaceId = "35130000001055707"
viewId = "35730000007354002"
)
func ImportBulkData(ac ZAnalytics.Client) {
config := map[string]interface{}{}
importtype := "truncateadd"
filetype := "csv"
autoidentify := "true"
filepath := "/home/local/admin/Files/Sales.csv"
bulk := ZAnalytics.GetBulkInstance(&ac, orgId, workspaceId)
result, err := bulk.ImportBulkData(viewId, importtype, filetype, autoidentify, filepath, config)
if(err != nil){
fmt.Println("Error - " + err.ErrorMessage)
}else{
fmt.Println(result)
}
}
func main() {
ac := ZAnalytics.GetAnalyticsClient(clientId, clientSecret, refreshToken)
ImportBulkData(ac)
}
Copiedimport com.zoho.analytics.client.*;
import org.json.*;
public class Test {
private long orgId = 55522777l;
private long workspaceId = 35130000001055707l;
private long viewId = 35730000007354002l;
public static void main(String args[]){
String clientId = "1000.xxxxxxx";
String clientSecret = "xxxxxxx";
String refreshToken = "1000.xxxxxxx.xxxxxxx";
Test tObj = new Test();
AnalyticsClient ac = new AnalyticsClient(clientId, clientSecret, refreshToken);
try {
tObj.importBulkData(ac);
}
catch (ServerException ex) {
System.out.println("Server exception - ErrorCode : " + ex.getErrorCode() + ", ErrorMessage : " + ex.getErrorMessage());
}
catch (ParseException ex) {
System.out.println("Parser exception - ErrorMessage : " + ex.getResponseMessage());
}
catch (Exception ex) {
System.out.println("Other exception - ");
ex.printStackTrace();
}
}
public void importBulkData(AnalyticsClient ac) throws Exception {
String importType = "TRUNCATEADD";
String fileType = "csv";
boolean autoIdentify = true;
String filePath = "/home/local/admin/Files/Sales.csv";
JSONObject config = new JSONObject();
BulkAPI data = ac.getBulkInstance(orgId, workspaceId);
long jobId = data.importBulkData(viewId, importType, fileType, autoIdentify, filePath, config);
System.out.println(jobId);
}
}
Copied<?php
require 'AnalyticsClient.php';
class Test
{
public $ac = NULL;
public $client_id = "1000.xxxxxxx";
public $client_secret = "xxxxxxx";
public $refresh_token = "1000.xxxxxxx.xxxxxxx";
public $org_id = "55522777";
public $workspace_id = "35130000001055707";
public $view_id = "35730000007354002";
function __construct() {
$this->ac = new AnalyticsClient($this->client_id, $this->client_secret, $this->refresh_token);
}
function importBulkData() {
$import_type = "truncateadd";
$file_type = "csv";
$auto_identify = "true";
$file_path = "/home/local/admin/Files/Sales.csv";
$bulk = $this->ac->getBulkInstance($this->org_id, $this->workspace_id);
$response = $bulk->importBulkData($this->view_id, $import_type, $file_type, $auto_identify, $file_path);
print_r($response);
}
}
$test_obj = new Test();
try {
$test_obj->importBulkData();
}
catch(ServerException $se) {
echo "Server exception : " . $se->getErrorMessage() . "\n";
}
catch(IOException $ioe) {
echo "IO exception : " . $ioe->getErrorMessage() . "\n";
}
catch(ParseException $pe) {
echo "Parser exception : " . $pe->getErrorMessage() . "\n";
}
catch(Exception $e) {
echo "Exception : " . $e->getErrorMessage() . "\n";
}
?>
Copiedfrom __future__ import with_statement
from AnalyticsClient import AnalyticsClient
import sys
import json
class Config:
CLIENTID = "1000.xxxxxxx";
CLIENTSECRET = "xxxxxxx";
REFRESHTOKEN = "1000.xxxxxxx.xxxxxxx";
ORGID = "55522777";
WORKSPACEID = "35130000001055707";
VIEWID = "35730000007354002";
class sample:
ac = AnalyticsClient(Config.CLIENTID, Config.CLIENTSECRET, Config.REFRESHTOKEN)
def import_bulk_data(self, ac):
import_type = "truncateadd"
file_type = "csv"
auto_identify = "true"
file_path = "/home/local/admin/Files/Sales.csv"
bulk = ac.get_bulk_instance(Config.ORGID, Config.WORKSPACEID)
result = bulk.import_bulk_data(Config.VIEWID, import_type, file_type, auto_identify, file_path)
print(result)
try:
obj = sample()
obj.import_bulk_data(obj.ac);
except Exception as e:
print(str(e))
Copiedvar analyticsClient = require('./AnalyticsClient');
var clientId = '1000.xxxxxxx';
var clientSecret = 'xxxxxxx';
var refreshtoken = '1000.xxxxxxx.xxxxxxx';
var orgId = '55522777';
var workspaceId = '35130000001055707';
var viewId = '35730000007354002';
var ac = new analyticsClient(clientId, clientSecret, refreshtoken);
var importType = 'append';
var fileType = 'csv';
var autoIdentify = true;
var filePath = '/home/local/admin/Files/Sales.csv';
var bulk = ac.getBulkInstance(orgId, workspaceId);
bulk.importBulkData(viewId, importType, fileType, autoIdentify, filePath).then((response) => {
console.log(response);
}).catch((error) => {
console.log('errorCode : '+error.errorCode);
console.log('errorMessage : '+error.errorMessage);
});
CopiedorgId = "55522777";
workspaceId = "35130000001055707";
viewId = "35730000007354002";
headersMap = Map();
headersMap.put("ZANALYTICS-ORGID",orgId);
fileResponse = invokeurl
[
url :""
type :GET
];
file = fileResponse.toFile("Sample.csv");
file.setParamName("FILE");
config = Map();
config.put("importType","append");
config.put("fileType","csv");
config.put("autoIdentify","true");
parameters = "CONFIG=" + zoho.encryption.urlEncode(config.toString());
response = invokeurl
[
url :"https://analyticsapi.zoho.com/restapi/v2/bulk/workspaces/" + workspaceId + "/views/" + viewId + "/data" + "?" + parameters
type :POST
headers:headersMap
files:file
connection:"analytics_oauth_connection"
];
info response;
Download client libraries: C# | GO | JAVA | PHP | PYTHON | NodeJS
Sample value for CONFIG parameter:
Copied{
"importType":"append",
"fileType":"csv",
"autoIdentify":"true"
}
Sample Response
CopiedHTTP/1.1 200 OK
Content-Type:application/json;charset=UTF-8
{
"status": "success",
"summary": "Create bulk import job",
"data": {
"jobId": "1757024000003153087"
}
}