Create Table
Create a table in the specified workspace.
REQUEST URI
https://<ZohoAnalytics_Server_URI>/restapi/v2/workspaces/<workspace-id>/tables
Post
oauthscope: ZohoAnalytics.modeling.create
QUERY PARAMETERS
| Description |
---|---|
CONFIG* | JSONObject Config parameter specifications are available in the below section. |
FIELDS FOR CONFIG JSON
Key | Description |
---|---|
tableDesign* | JSONObject <Table Structure> |
TABLE STRUCTURE
Key | Description |
---|---|
TABLENAME* | String The name of the table. |
TABLEDESCRIPTION | String The description of the table. |
FOLDERNAME | String The name of the folder where the table have to be created. |
COLUMNS* | JSONArray Column Structure |
Key | Description |
---|---|
COLUMNNAME* | String The name of the column. |
DATATYPE* | String
|
MANDATORY | Boolean Controls whether the column should contain a mandatory non-empty value. Default value - false. |
DESCRIPTION | String The description of the column. |
DEFAULT | String Default value for the column Fills the provided value when a cell in the column is empty. |
GEOROLE | Integer
|
ISHIDE | Boolean Controls whether the column should be visible or not. Default value - false |
PII | Boolean To mark the column as 'Personal Data Column'. Default value - false |
LOOKUPCOLUMN | JSONObject Add a lookup to the specified reference table. Check the table LOOKUPCOLUMN for more details. |
Key | Description |
---|---|
TABLENAME* | String The name of the reference table. |
COLUMNNAME* | String The name of the reference column. |
POSSIBLE ERROR CODES
Sample Request:
Copiedcurl https://analyticsapi.zoho.com/restapi/v2/workspaces/<workspace-id>/tables?CONFIG=<encoded_json_value>
-X 'POST'
-H 'ZANALYTICS-ORGID: <org-id>'
-H 'Authorization: Zoho-oauthtoken <access_token>'
Copiedusing System;
using System.Collections.Generic;
using ZohoAnalytics;
namespace ZohoAnalyticsTest
{
class Program
{
long orgId = 55522777;
long workspaceId = 35130000001055707;
public void CreateTable(IAnalyticsClient ac)
{
Dictionary<string, object> tableDesign = new Dictionary<string, object>();
tableDesign.Add("TABLENAME", "Test C#");
tableDesign.Add("TABLEDESCRIPTION", "Test C# Desc");
List<Dictionary<string, object>> columns = new List<Dictionary<string, object>>();
Dictionary<string, object> column1 = new Dictionary<string, object>();
column1.Add("COLUMNNAME", "Col1");
column1.Add("DATATYPE", "PLAIN");
Dictionary<string, object> column2 = new Dictionary<string, object>();
column2.Add("COLUMNNAME", "Col2");
column2.Add("DATATYPE", "NUMBER");
columns.Add(column1);
columns.Add(column2);
tableDesign.Add("COLUMNS", columns);
IWorkspaceAPI ws = ac.GetWorkspaceInstance(orgId, workspaceId);
long viewId = ws.CreateTable(tableDesign);
Console.WriteLine(viewId);
}
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.CreateTable(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"
)
func CreateTable(ac ZAnalytics.Client) {
tableDesign := map[string]interface{}{}
tableDesign["TABLENAME"] = "Table Name"
tableDesign["TABLEDESCRIPTION"] = "Description"
type column map[string]interface{}
column1 := column{"COLUMNNAME":"Col1", "DATATYPE":"PLAIN"}
column2 := column{"COLUMNNAME":"Col2", "DATATYPE":"NUMBER"}
var columns []column
columns = append(columns, column1, column2)
tableDesign["COLUMNS"] = columns
workspace := ZAnalytics.GetWorkspaceInstance(&ac, orgId, workspaceId)
result, exception := workspace.CreateTable(tableDesign)
if(exception != nil){
fmt.Println(exception.ErrorMessage)
}else{
fmt.Println(result)
}
}
func main() {
ac := ZAnalytics.GetAnalyticsClient(clientId, clientSecret, refreshToken)
CreateTable(ac)
}
Copiedimport com.zoho.analytics.client.*;
import org.json.*;
public class Test {
private long orgId = 55522777l;
private long workspaceId = 35130000001055707l;
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.createTable(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 createTable(AnalyticsClient ac) throws Exception {
WorkspaceAPI workspace = ac.getWorkspaceInstance(orgId, workspaceId);
JSONObject tableDesign = new JSONObject();
tableDesign.put("TABLENAME", "SalesTable");
tableDesign.put("TABLEDESCRIPTION", "Description");
JSONObject column1 = new JSONObject();
column1.put("COLUMNNAME", "Column 1");
column1.put("DATATYPE", "PLAIN");
JSONObject column2 = new JSONObject();
column2.put("COLUMNNAME", "Column 2");
column2.put("DATATYPE", "NUMBER");
JSONArray columns = new JSONArray();
columns.put(column1);
columns.put(column2);
tableDesign.put("COLUMNS", columns);
long result = workspace.createTable(tableDesign);
System.out.println(result);
}
}
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";
function __construct() {
$this->ac = new AnalyticsClient($this->client_id, $this->client_secret, $this->refresh_token);
}
function createTable() {
$table_design = array();
$table_design["TABLENAME"] = "Sample";
$table_design["TABLEDESCRIPTION"] = "Description";
$column1 = array();
$column1["COLUMNNAME"] = "Col1";
$column1["DATATYPE"] = "PLAIN";
$column2 = array();
$column2["COLUMNNAME"] = "Col2";
$column2["DATATYPE"] = "NUMBER";
$columns = array($column1, $column2);
$table_design["COLUMNS"] = $columns;
$workspace = $this->ac->getWorkspaceInstance($this->org_id, $this->workspace_id);
$response = $workspace->createTable($table_design);
print_r($response);
}
}
$test_obj = new Test();
try {
$test_obj->createTable();
}
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";
class sample:
ac = AnalyticsClient(Config.CLIENTID, Config.CLIENTSECRET, Config.REFRESHTOKEN)
def create_table(self, ac):
columns_arr = []
column1 = {}
column1["COLUMNNAME"] = "Col1"
column1["DATATYPE"] = "PLAIN"
column2 = {}
column2["COLUMNNAME"] = "Col2"
column2["DATATYPE"] = "NUMBER"
columns_arr.append(column1)
columns_arr.append(column2)
table_design = {}
table_design["TABLENAME"] = "Created Table"
table_design["COLUMNS"] = columns_arr
workspace = ac.get_workspace_instance(Config.ORGID, Config.WORKSPACEID)
result = workspace.create_table(table_design)
print(result)
try:
obj = sample()
obj.create_table(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 ac = new analyticsClient(clientId, clientSecret, refreshtoken);
var columnsArray = [];
var column1 = {};
column1["COLUMNNAME"] = "Col1";
column1["DATATYPE"] = "PLAIN";
columnsArray.push(column1);
var column2 = {};
column2["COLUMNNAME"] = "Col2";
column2["DATATYPE"] = "NUMBER";
columnsArray.push(column2);
var tableDesign = {};
tableDesign["TABLENAME"] = "Created";
tableDesign["COLUMNS"] = columnsArray;
var workspace = ac.getWorkspaceInstance(orgId, workspaceId);
workspace.createTable(tableDesign).then((response) => {
console.log(response);
}).catch((error) => {
console.log('errorCode : '+error.errorCode);
console.log('errorMessage : '+error.errorMessage);
});
CopiedorgId = "55522777";
workspaceId = "35130000001055707";
headersMap = Map();
headersMap.put("ZANALYTICS-ORGID",orgId);
tableDesign = Map();
tableDesign.put("TABLENAME","Test Table");
tableDesign.put("TABLEDESCRIPTION","Table Description");
column1 = Map();
column1.put("COLUMNNAME","Col1");
column1.put("DATATYPE","PLAIN");
column2 = Map();
column2.put("COLUMNNAME","Col2");
column2.put("DATATYPE","NUMBER");
columns = {};
columns.add(column1);
columns.add(column2);
tableDesign.put("COLUMNS",columns);
design = Map();
design.put("tableDesign",tableDesign);
paramsMap = Map();
paramsMap.put("CONFIG",design.toString());
response = invokeurl
[
url :"https://analyticsapi.zoho.com/restapi/v2/workspaces/" + workspaceId + "/tables"
type :POST
parameters:paramsMap
headers:headersMap
connection:"analytics_oauth_connection"
];
info response;
Sample value for CONFIG parameter:
Copied{
"tableDesign": {
"TABLENAME": "Sales",
"TABLEDESCRIPTION": "Test",
"COLUMNS": [{
"COLUMNNAME": "Column1",
"DATATYPE": "PLAIN"
}, {
"COLUMNNAME": "Column2",
"DATATYPE": "NUMBER"
}]
}
}
Sample Response:
CopiedHTTP/1.1 200 OK
Content-Type:application/json;charset=UTF-8
{
"status": "success",
"summary": "Create table",
"data": {
"viewId": "1767024000003145011"
}
}