Update Variable

Update details of the specified variable.

REQUEST URI

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

Put

oauthscopeZohoAnalytics.modeling.update

QUERY PARAMETERS

 

Parameter Name
Description
CONFIG*JSONObject

Config parameter specifications are available in the below section.

FIELDS FOR CONFIG JSON

KeyDescription
variableName*String

New name of the variable.
variableDatatype*

Integer

New datatype of the variable.

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

Integer

New 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/<variable-id>?CONFIG=<encoded_json_value> 
-X 'PUT' 
-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 UpdateVariable(IAnalyticsClient ac)
        {
            long variableId = 1148746000002545001;
            string variableName = "Variable_NEW_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("4");
            values_1.Add("5");
            values_1.Add("6");

            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("1");
            values_2.Add("2");
            values_2.Add("3");

            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);
            workspace.UpdateVariable(variableId, variableName, variableDataType, variableType, config);
            Console.WriteLine("success");
        }

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

            try
            {
                IAnalyticsClient ac = new AnalyticsClient(clientId, clientSecret, refreshToken);
                Program obj = new Program();
                obj.UpdateVariable(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 UpdateVariable(ac ZAnalytics.Client) {
    variableid:= "1767024000004594001"
    variablename:= "Variable_11"
    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)
    exception := workspace.UpdateVariable(variableid, variablename, variabledatatype, variabletype, config)

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

func main() {

    ac := ZAnalytics.GetAnalyticsClient(clientId, clientSecret, refreshToken)
    UpdateVariable(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.updateVariable(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 updateVariable(AnalyticsClient ac) throws Exception {
        long variableId = 0l;
        String variableName = "Variable_2";
        int variableDataType = 1;
        int variableType = 3;

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

        JSONArray values_1 = new JSONArray();
        values_1.put("11");
        values_1.put("12");

        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("13");
        values_2.put("14");

        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);
        workspace.updateVariable(variableId, variableName, variableDataType, variableType, config);
        System.out.println("success");
    }
}
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 updateVariable() {
            $variable_id = "1767024000004613001";
            $variable_name = "Variable 11";
            $variable_datatype = "1";
            $variable_type = "3";

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

            $values_1 = array("11", "12");
            $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("13", "14");
            $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);
            $workspace->updateVariable($variable_id, $variable_name, $variable_datatype, $variable_type, $config);
            echo "success\n";
        }
    }

    $test_obj = new Test();

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

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

        values_1 = []
        values_1.append("11")
        values_1.append("12")

        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("13")
        values_2.append("14")

        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)
        workspace.update_variable(variable_id, variable_name, variable_datatype, variable_type, config)           
        print("success")

try:
    obj = sample()
    obj.update_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 variableId = '';
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.updateVariable(variableId, variableName, variableDataType, variableType, config).catch((error) => {
    console.log('errorCode : '+error.errorCode);
    console.log('errorMessage : '+error.errorMessage);
});
CopiedorgId = "55522777";
workspaceId = "35130000001055707";
variableId = "";
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);

parameters = "CONFIG=" + zoho.encryption.urlEncode(config.toString());

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

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 204 No Content