Copy Formula

The Copy Formula API is used to copy one or more formula columns from one table to another within the same Workspace or across Workspaces and even across one user account to another. The source workspace administrator should generate and provide the Copy Workspace Key, the secret key used to authorize the destination workspace administrator. It is necessary that the table and column name in the destination Workspace should be the same as that of the table and column names in the source Workspace on which the formula is dependent. Both Custom Formula and Aggregate Formula can be copied using this API.

REQUEST URI

https://<ZohoAnalytics_Server_URI>/api/<SourceEmail>/<SourceWorkspaceName>/SourceTableName

Post

oauthscope: ZohoAnalytics.modeling.create

COMMON PARAMETERS

ParameterPossible ValuesDescription
ZOHO_ACTIONCOPYFORMULAThis parameter specifies the action to be performed by the API request.
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 (DATA FOR THE ROW)

ParameterPossible ValuesDescription
ZOHO_FORMULATOCOPY Formula name

 This parameter holds the FORMULA NAME to be copied from the source Workspace into another table in the destination Workspace.

In case more than one formulas are to be copied, the formula names should be separated by comma ( , ).

Example: ZOHO_FORMULATOCOPY=MyFormula1,MyFormula2,MyFormulaN

ZOHO_DATABASE_NAME  Workspace name

This parameter holds the name of the Workspace (destination Workspace) where the destination table is present.

The specified formula are copied to the table which has same name (SourceEmployeeDetails) as specified in the API URL

ZOHO_COPY_DB_KEY  Workspace key

The secret key used for allowing the user to copy the Workspace / Reports.

The source Workspace admin has to create the Copy Workspace Secret Key. For more about Workspace key.

Note: You need to provide the appropriate values in the above URL to generate the corresponding Copy Workspace Key for your setup

POSSIBLE ERROR CODES

7103 , 7138 , 8504 , 8506 , 8516 , 8533 , 15002 , 15007 , 15009 , 15010

Sample Request:

Copiedcurl 
-d "ZOHO_ACTION=COPYFORMULA&ZOHO_OUTPUT_FORMAT=XML&ZOHO_ERROR_FORMAT=XML&ZOHO_API_VERSION=1.0&ZOHO_FORMULATOCOPY=Formula1&ZOHO_DATABASE_NAME=Destination Workspace Name&ZOHO_COPY_DB_KEY=*************" 
-H "Authorization:Zoho-oauthtoken <access_token>" 
https://analyticsapi.zoho.com/api/EmailAddress/WorkspaceName/TableName
Copiedusing ZReports;

namespace Test
{
    CLIENT_ID = "************";
    CLIENT_SECRET = "************";
    REFRESH_TOKEN = "************";
    EMAIL = "Email Address";
    DBNAME = "Workspace Name";
    TBNAME = "Table Name";

    class Program
    {
        public IReportClient getClient()
        {
            IReportClient RepClient = new ReportClient(CLIENT_ID, CLIENT_SECRET, REFRESH_TOKEN);
            return RepClient;
        }

        public void copyformula(IReportClient rc)
        {
            string uri = rc.GetURI(EMAIL, DBNAME, TBNAME);
            string formula = "Formula1,Formula2";
            string dbname = "Destination Workspace Name";
            string dbkey = "***********";
            rc.CopyFormula(uri, formula, dbname, dbkey, null);
        }

        static void Main(string[] args)
        {
            Program obj = new Program();
            IReportClient rc = obj.getClient();
            obj.copyformula(rc);
        }
    }
}
Copiedpackage main

import (
	"fmt"
	"zoho/pkg/reportclient"
)

var (
	email        = "Email Address"
	dbname       = "Workspace Name"
	tbname       = "Table Name"
	clientid     = "************"
	clientsecret = "************"
	refreshtoken = "************"
	dbkey        = "************"
)

func copyformula() {
	url := reportclient.GetUri(email, dbname, tbname)
	formulaname := "Formula1,Formula2"
	destdbname := "Destination Workspace Name"
	err := reportclient.CopyFormula(url, formulaname, destdbname, dbkey)
	if err != nil {
		fmt.Println(err.ErrorMessage)
		fmt.Println(err.ErrorCode)
		fmt.Println(err.Action)
		fmt.Println(err.HttpStatusCode)
	} else {
		fmt.Println("Success")
	}
}

func main() {
	reportclient.SetOAuthToken(clientid, clientsecret, refreshtoken)
	copyformula()
}
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 = "************";
    String dbkey = "*************";
    String destdb = "Formula1";
    String formula = "Destination Workspace Name";
    Map config = new HashMap();
    private ReportClient rc = new ReportClient(clientId, clientSecret, refreshToken);

    public void copyformula() throws Exception {
        String uri = rc.getURI(email, dbname, tbname);
        rc.copyFormula(uri, formula, destdb, dbkey, config);
    }

    public static void main(String[] args) throws Exception {
        Sample obj = new Sample();
        obj.copyformula();
    }
}
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);
$formula = "Formula1";
$dbname = "Destination Workspace Name";
$dbkey = "*************";
$report_client_request->copyFormula($uri, $formula, $dbname, $dbkey);
?>
Copiedfrom __future__ import with_statement
from ReportClient import ReportClient
import sys

class Sample:
    LOGIN_EMAIL_ID = "Email Address"
    DATABASE_NAME = "Workspace Name"
    TABLE_NAME = "Table Name"
    rc = None
    rc = ReportClient(REFRESH_TOKEN, CLIENT_ID, CLIENT_SECRET)

    def copyformula(self, rc):
        uri = rc.getURI(self.LOGIN_EMAIL_ID, self.DATABASE_NAME, self.TABLE_NAME)
        rc.copyFormula(uri, "Formula1", "Destination Workspace Name", "************")

    obj = Sample()
    obj.copyformula(obj.rc)
Copiedvar nodelib = require('./ZAnalyticsClient');
var clientId = '************';
var clientSecret = '************';
var refreshtoken = '************';
var emailId = 'EmailAddress';
var workspaceName = 'WorkspaceName';
var viewName = 'ViewName';
var copydbkey = '';
nodelib.initialize(clientId, clientSecret, refreshtoken).then(() => {
    var params = {};
    var uripath = nodelib.getUri(emailId, workspaceName, viewName);
    var destWorkspaceName = '';
    var formulaNames = '';
    nodelib.copyFormula(formulaNames, destWorkspaceName, copydbkey, 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:POSTparameters:oauthParams];
if (tokenInfo.containKey("access_token")) {
    accessToken = tokenInfo.get("access_token");
    headers.put("Authorization", "Zoho-oauthtoken ".concat(accessToken));
} else {
    info tokenInfo;
    return;
}

// COMMON PARAMS
paramsMap.put("ZOHO_ACTION", "COPYFORMULA");
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_FORMULATOCOPY", "");
paramsMap.put("ZOHO_DATABASE_NAME", "");
paramsMap.put("ZOHO_COPY_DB_KEY", "");
response = invokeurl[url: "https://analyticsapi.zoho.com/api/" + email + "/" + workspaceName + "/" + viewName
    type: POST parameters: paramsMap headers: headers];
info response;

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

Sample Response:

Copied<responseuri="/api/EmailAddress/WorkspaceName/TableName"action="COPYFORMULA">
    <result>
        <message>
        Successfully formula(s) Copied
        </message>
    </result>
</response>
Copied{"response":
         {"uri":"\/api\/email\/Workspace name\/TableName",
            "action":"COPYFORMULA",
            "result":
        {"message": "Successfully Formula(s) Copied"}}}