Start here
Getting started
Install the SDK, construct a client, and make a first authenticated call.
Install#
Place the package under your module as zoho/pkg/analyticsclient and import it:
import ZAnalytics "zoho/pkg/analyticsclient"Go returns errors rather than raising them: every method returns a trailing *ServerException which is nil on success.
Register an OAuth client#
- Open the Zoho API Console for your data center.
- Create a Self Client for server-to-server integrations, or a Server-based Application if users will authorise your app themselves.
- Note the Client ID and Client Secret.
- Generate a refresh token with the scopes your integration needs — see Authentication.
Construct the client#
package main
import (
"fmt"
ZAnalytics "zoho/pkg/analyticsclient"
)
var (
clientId = "1000.xxxxxxx"
clientSecret = "xxxxxxx"
refreshToken = "1000.xxxxxxx.xxxxxxx"
)
ac := ZAnalytics.GetAnalyticsClient(clientId, clientSecret, refreshToken)Get a scoped instance#
The client hands out four scoped objects. Each one binds the identifiers it needs, so you do not repeat them on every call.
org := ZAnalytics.GetOrgInstance(&ac, orgId)
workspace := ZAnalytics.GetWorkspaceInstance(&ac, orgId, workspaceId)
view := ZAnalytics.GetViewInstance(&ac, orgId, workspaceId, viewId)
bulk := ZAnalytics.GetBulkInstance(&ac, orgId, workspaceId)| Instance | Bound to | Use for |
|---|---|---|
OrgAPI | organization | Users, roles, admins, subscription, security controls. |
WorkspaceAPI | organization + workspace | Views, folders, schedules, alerts, backups, sharing. |
ViewAPI | organization + workspace + view | Rows, columns, formulas, publishing. |
BulkAPI | organization + workspace | Importing and exporting data. |
Make a first call#
ac := ZAnalytics.GetAnalyticsClient(clientId, clientSecret, refreshToken)
org := ZAnalytics.GetOrgInstance(&ac, orgId)
workspaces, exception := org.GetOrgWorkspaces()
if exception != nil {
fmt.Printf("HTTP %d / %v: %s\n",
exception.HttpStatusCode, exception.ErrorCode, exception.ErrorMessage)
return
}
fmt.Println(workspaces)A successful call returns the data payload of the response envelope, already decoded. A failure raises or returns A returned *ServerException with ErrorCode, ErrorMessage, HttpStatusCode and Action..
Sample response#
{
"status": "success",
"summary": "Get organizations",
"data": {
"orgs": [
{
"orgId": "55522777",
"orgName": "Zylker Analytics",
"orgDesc": "",
"timeZone": "Asia/Kolkata",
"role": "ORGADMIN"
}
]
}
}The SDK unwraps the envelope for you: the value you receive is the contents of data.orgs, not the whole document above.
Where to go next#
- Authentication — read the token throttle section before you ship.
- Errors — what to branch on when a call fails.
- Importing data — the three import modes and when to use each.