Create Variable

Create a variable in the specified workspace.

REQUEST URI

https://<ZohoAnalytics_Server_URI>/restapi/v2/workspaces/<workspace-id>/variables

Post

oauthscopeZohoAnalytics.modeling.create

QUERY PARAMETERS

 

Parameter Name
Description
CONFIG*JSONObject

Config parameter specifications are available in the below section.

FIELDS FOR CONFIG JSON

KeyDescription
variableName*String

Name of the variable.
variableDatatype*

Integer

Datatype of the variable.

  • 1 - PLAIN
  • 4 - NUMBER
  • 5 - POSITIVE_NUMBER
  • 6 - DECIMAL_NUMBER
  • 7 - CURRENCY
  • 8 - PERCENT
variableType*

Integer

Type of the variable.

  • 0 - LIST
  • 1 - RANGE
  • 3 - ALL_VALUES
formatJSONObject

Variable format.
Refer FORMAT JSON Structure.
userSpecificDataJSONArray

Array of user specfic values.
Refer USER_SPECIFIC_DATA JSON Structure.
defaultDataJSONObject

Default value for the variable.
Mandatory for LIST and RANGE variable type.
Refer DEFAULT_DATA JSON Structure.

FORMAT STRUCTURE

KeyDescription
alignment

String
 

  • Left
  • Center
  • Right
decimalPlacesInteger

-1 to 10
currencySymbolString

<CURRENCY_SYMBOL>
Sample : en;US;
showNegativeSignBoolean

true / false
userLocaleBoolean

true / false
thousandSeparator

Integer
 

  • 0 - NONE
  • 1 - COMMA
  • 2 - DOT
  • 3 - SPACE
  • 4 - SINGLE_QUOTE
decimalSeparator

Integer
 

  • 0 - DOT
  • 1 - COMMA
showPercentBoolean

true / false
Valid only for PERCENT format type.

USER_SPECIFIC_DATA STRUCTURE

KeyDescription
valuesJSONArray

Array of values
Sample : ["Value_1","Value_2"]
emailIdsJSONArray

Array of EmailIds
Sample : ["user+1@zoho.com","user+2@zoho.com"]
defaultValueString

Default value for the variable.
Mandatory for RANGE variable type.
minValueString

Minimum value for the variable.
Mandatory for RANGE variable type.
maxValueString

Maximum value for the variable.
Mandatory for RANGE variable type.
stepSizeString

Incremental value for the variable.
Mandatory for RANGE variable type.
domainNameString

Name of the domain
To add variable values to the white label domain users.

DEFAULT_DATA STRUCTURE

KeyDescription
valuesJSONArray

Array of values
Sample : ["Value_1","Value_2"]
Mandatory for LIST variable type.
defaultValueString

Default value for the variable.
Mandatory for RANGE variable type.
minValueString

Minimum value for the variable.
Mandatory for RANGE variable type.
maxValueString

Maximum value for the variable.
Mandatory for RANGE variable type.
stepSizeString

Incremental value for the variable.
Mandatory for RANGE variable type.

POSSIBLE ERROR CODES

7103, 7301, 8083, 8504, 8516, 8518, 8535, 70323

Sample Request:

Copiedcurl https://analyticsapi.zoho.com/restapi/v2/workspaces/<workspace-id>/variables?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 = 67648404;
        long workspaceId = 1148746000002449012;

        public void CreateVariable(IAnalyticsClient ac)
        {
            string variableName = "Variable_1";
            int variableDataType = 1;
            int variableType = 3;

            Dictionary<string, object> format = new Dictionary<string, object>();
            format.Add("alignment", "left");

            List<string> emailIds_1 = new List<string>();
            emailIds_1.Add("user+1@zoho.com");
            emailIds_1.Add("user+2@zoho.com");

            List<string> values_1 = new List<string>();
            values_1.Add("1");
            values_1.Add("2");
            values_1.Add("3");

            Dictionary<string, object> dataset_1 = new Dictionary<string, object>();
            dataset_1.Add("values", values_1);
            dataset_1.Add("emailIds", emailIds_1);

            List<string> emailIds_2 = new List<string>();
            emailIds_2.Add("user+3@zoho.com");
            emailIds_2.Add("user+4@zoho.com");

            List<string> values_2 = new List<string>();
            values_2.Add("4");
            values_2.Add("5");
            values_2.Add("6");

            Dictionary<string, object> dataset_2 = new Dictionary<string, object>();
            dataset_2.Add("values", values_2);
            dataset_2.Add("emailIds", emailIds_2);

            List<object> userSpecificData = new List<object>();
            userSpecificData.Add(dataset_1);
            userSpecificData.Add(dataset_2);

            Dictionary<string, object> config = new Dictionary<string, object>();
            config.Add("format", format);
            config.Add("userSpecificData", userSpecificData);

            IWorkspaceAPI workspace = ac.GetWorkspaceInstance(orgId, workspaceId);
            long variableId = workspace.CreateVariable(variableName, variableDataType, variableType, config);
            Console.WriteLine(variableId);
        }

        static void Main(string[] args)
        {
            string clientId = "";
            string clientSecret = "";
            string refreshToken = "";

            try
            {
                IAnalyticsClient ac = new AnalyticsClient(clientId, clientSecret, refreshToken);
                Program obj = new Program();
                obj.CreateVariable(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 CreateVariable(ac ZAnalytics.Client) {
    variablename:= "Variable_1"
    variabledatatype:= 1
    variabletype:= 3

    values_1 := [2]string{}
    values_1[0] = "1"
    values_1[1] = "2"

    emailids_1 := [1]string{}
    emailids_1[0] = "user+1@zoho.com"

    dataset_1 := map[string]interface{}{}
    dataset_1["values"] = values_1
    dataset_1["emailIds"] = emailids_1

    values_2 := [2]string{}
    values_2[0] = "3"
    values_2[1] = "4"

    emailids_2 := [1]string{}
    emailids_2[0] = "user+2@zoho.com"

    dataset_2 := map[string]interface{}{}
    dataset_2["values"] = values_2
    dataset_2["emailIds"] = emailids_2

    userspecificdata := [2]map[string]interface{}{}
    userspecificdata[0] = dataset_1
    userspecificdata[1] = dataset_2

    format := map[string]interface{}{}
    format["alignment"] = "left"

    config := map[string]interface{}{}
    config["userSpecificData"] = userspecificdata
    config["format"] = format


    workspace := ZAnalytics.GetWorkspaceInstance(&ac, orgId, workspaceId)
    result, exception := workspace.CreateVariable(variablename, variabledatatype, variabletype, config)

    if(exception != nil){
        fmt.Println(exception.ErrorMessage)
    }else{
        fmt.Println(result)
    }
}

func main() {

    ac := ZAnalytics.GetAnalyticsClient(clientId, clientSecret, refreshToken)
    CreateVariable(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.createVariable(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 createVariable(AnalyticsClient ac) throws Exception {
        String variableName = "Variable_1";
        int variableDataType = 1;
        int variableType = 3;

        JSONObject format = new JSONObject();
        format.put("alignment", "left");

        JSONArray values_1 = new JSONArray();
        values_1.put("1");
        values_1.put("2");

        JSONArray emailIds_1 = new JSONArray();
        emailIds_1.put("user+1@zoho.com");
        emailIds_1.put("user+2@zoho.com");

        JSONArray values_2 = new JSONArray();
        values_2.put("3");
        values_2.put("4");

        JSONArray emailIds_2 = new JSONArray();
        emailIds_2.put("user+3@zoho.com");
        emailIds_2.put("user+4@zoho.com");

        JSONObject dataset_1 = new JSONObject();
        dataset_1.put("values", values_1);
        dataset_1.put("emailIds", emailIds_1);

        JSONObject dataset_2 = new JSONObject();
        dataset_2.put("values", values_2);
        dataset_2.put("emailIds", emailIds_2);

        JSONArray userSpecificData = new JSONArray();
        userSpecificData.put(dataset_1);
        userSpecificData.put(dataset_2);

        JSONObject config = new JSONObject();
        config.put("format", format);
        config.put("userSpecificData", userSpecificData);


        WorkspaceAPI workspace = ac.getWorkspaceInstance(orgId, workspaceId);
        long result = workspace.createVariable(variableName, variableDataType, variableType, config);
        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 createVariable() {
            $variable_name = "Variable 2";
            $variable_datatype = "1";
            $variable_type = "3";

            $format = array();
            $format["alignment"] = "left";

            $values_1 = array("1", "2");
            $email_ids_1 = array("user+1@zohotest.com", "user+2@zohotest.com");

            $dataset_1 = array();
            $dataset_1["values"] = $values_1;
            $dataset_1["emailIds"] = $email_ids_1;

            $values_2 = array("3", "4");
            $email_ids_2 = array("user+3@zohotest.com", "user+4@zohotest.com");

            $dataset_2 = array();
            $dataset_2["values"] = $values_2;
            $dataset_2["emailIds"] = $email_ids_2;

            $user_specific_data = array($dataset_1, $dataset_2);

            $config = array();
            $config["format"] = $format;
            $config["userSpecificData"] = $user_specific_data;

            $workspace = $this->ac->getWorkspaceInstance($this->org_id, $this->workspace_id);
            $response =  $workspace->createVariable($variable_name, $variable_datatype, $variable_type, $config);
            print_r($response);
        }
    }

    $test_obj = new Test();

    try {
        $test_obj->createVariable();
    }
    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_variable(self, ac):
        variable_name = "Variable 1"
        variable_datatype = "1"
        variable_type = "3"

        variable_format = {}
        variable_format["alignment"] = "left"

        values_1 = []
        values_1.append("1")
        values_1.append("2")

        email_ids_1 = []
        email_ids_1.append("user+1@zoho.com")
        email_ids_1.append("user+2@zoho.com")

        dataset_1 = {}
        dataset_1["values"] = values_1
        dataset_1["emailIds"] = email_ids_1

        values_2 = []
        values_2.append("3")
        values_2.append("4")

        email_ids_2 = []
        email_ids_2.append("user+3@zoho.com")
        email_ids_2.append("user+4@zoho.com")

        dataset_2 = {}
        dataset_2["values"] = values_2
        dataset_2["emailIds"] = email_ids_2

        user_specific_data = []
        user_specific_data.append(dataset_1)
        user_specific_data.append(dataset_2)

        config = {}
        config["format"] = variable_format
        config["userSpecificData"] = user_specific_data

        workspace = ac.get_workspace_instance(Config.ORGID, Config.WORKSPACEID)
        result = workspace.create_variable(variable_name, variable_datatype, variable_type, config)           
        print(result)

try:
    obj = sample()
    obj.create_variable(obj.ac);

except Exception as e:
    print(str(e))
Copiedvar nodelib = require('./ZAnalyticsClient');

var clientId = '1000.xxxxxxx';
var clientSecret = 'xxxxxxx';
var refreshtoken = '1000.xxxxxxx.xxxxxxx';
var orgId = '55522777';
var workspaceId = '35130000001055707';
var variableName = "Variable_1";
var variableDataType = 1;
var variableType = 3;

var ac = new analyticsClient(clientId, clientSecret, refreshtoken);

var format = {};
format["alignment"] = "left";

var values_1 = [];
values_1.push("1");
values_1.push("2");

var emailIds_1 = [];
emailIds_1.push("user+1@zoho.com");
emailIds_1.push("user+2@zoho.com");

var dataset_1 = {};
dataset_1["values"] = values_1;
dataset_1["emailIds"] = emailIds_1;

var values_2 = [];
values_2.push("3");
values_2.push("4");

var emailIds_2 = [];
emailIds_2.push("user+3@zoho.com");
emailIds_2.push("user+4@zoho.com");

var dataset_2 = {};
dataset_2["values"] = values_2;
dataset_2["emailIds"] = emailIds_2;

var userSpecificData = [];
userSpecificData.push(dataset_1);
userSpecificData.push(dataset_2);

var config = {};
config["format"] = format;
config["userSpecificData"] = userSpecificData;

var workspace = ac.getWorkspaceInstance(orgId, workspaceId);
workspace.createVariable(variableName, variableDataType, variableType, config).then((response) => {
    console.log(response);

}).catch((error) => {
    console.log('errorCode : '+error.errorCode);
    console.log('errorMessage : '+error.errorMessage);
});
CopiedorgId = "55522777";
workspaceId = "35130000001055707";
variableName = "Variable_1";
variableDataType = 1;
variableType = 3;

headersMap = Map();
headersMap.put("ZANALYTICS-ORGID",orgId);

format = Map();
format.put("alignment", "left");

values_1 = {};
values_1.add("1");
values_1.add("2");

emailIds_1 = {};
emailIds_1.add("user+1@zoho.com");
emailIds_1.add("user+2@zoho.com");

dataset_1 = Map();
dataset_1.put("values", values_1);
dataset_1.put("emailIds", emailIds_1);

values_2 = {};
values_2.add("1");
values_2.add("2");

emailIds_2 = {};
emailIds_2.add("user+1@zoho.com");
emailIds_2.add("user+2@zoho.com");

dataset_2 = Map();
dataset_2.put("values", values_2);
dataset_2.put("emailIds", emailIds_2);

userSpecificData = {};
userSpecificData.add(dataset_1);
userSpecificData.add(dataset_2);

config = Map();
config.put("format", format);
config.put("userSpecificData", userSpecificData);

paramsMap = Map();
paramsMap.put("CONFIG",config.toString());

response = invokeurl
[
  url :"https://analyticsapi.zoho.com/restapi/v2/workspaces/" + workspaceId + "/variables"
  type :POST
  parameters:paramsMap
  headers:headersMap
  connection:"analytics_oauth_connection"
];
info response;

Download client libraries:  C# | GO | JAVA | PHP | PYTHON | NodeJS

Sample value for CONFIG parameter:

Copied{
   "variableName":"Variable - 1",
   "variableType":3,
   "variableDataType":1,
   "userSpecificData":[
      {
         "values":[
            "4",
            "5",
            "6"
         ],
         "emailIds":[
            "user+1@zohotest.com"
         ]
      },
      {
         "values":[
            "1",
            "2",
            "3"
         ],
         "emailIds":[
            "user+2@zohotest.com"
         ]
      }
   ],
   "format":{
      "alignment":"Left"
   }
}

Sample Response:

CopiedHTTP/1.1 200 OK
Content-Type:application/json;charset=UTF-8

{
   "status":"success",
   "summary":"Create variable",
   "data":{
      "variableId":"137687000006991651"
   }
}