Skip to content

zoholab is a go libary that can be used to call the zoho API.

Notifications You must be signed in to change notification settings

Clarilab/zoholab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🔍 zoholab

zoholab is a go libary that can be used to call the zoho API. The motivation to do this project stems from an issue we ran into while developing a way to track data in zoho analytics via their provided go client. While the client does work there were major improvements that needed to be made for us to be able to use it in our code. This is an improved take of this client with the feartures that we currently need, made with the intent of improving the go client for zoho.

💡 Improvements over offical zoho go client

  • Added a service struct
  • Replace net/http calls with resty calls
  • Remove panics from code
  • Replace throwing of ServerExceptions with standard error handling
  • Removed global variables

👷‍♀️ Features

Currently you are able to add a row to a table within zoho analytics. Some new functions might follow if needed.

🤯 Usage

Before using: Follow the steps in the zoho analytics documentation to create a new client and your refresh token. Make sure you create a table that you want to add your data into.

✅ You will need

  • Client ID
  • Client Secret
  • Refresh token
  • Email address in which the workspace is in
  • Workspace name
  • Table name

Make sure the client that you have created has the correct permissions to access the table that you want to modify.

Installation

go get github.com/Clarilab/zoholab

🛳 Import

import "github.com/Clarilab/zoholab"

😍 Initilise zoholab

func main() {
	zohoService := zoho.NewZohoService()

	zohoService.SetServiceParams(Clientid, Clientsecret, Refreshtoken)
}

🚣 Code Example for adding a row

func addRow(zohoService *zoholab.ZohoService) error {
	const errMessage = "could not add row"

	url := zoholab.GetUri(email, workspace, tbname)

	columnvalues := map[string]string{
		"your column name": "your column entry",
	}

	addedrows, err := zoholab.AddRow(url, columnvalues)
	if err != nil {
		return errors.Wrap(err, errMessage)
	}

	return nil
}

Code Example to upload a csv-bulk

zohoService := zoholab.NewZohoService()
zohoService.SetServiceParams(clientid, clientsecret, refreshtoken)
url := zohoService.GetUri(email, workspace, tbname)
params := map[string]string{
	"ZOHO_MATCHING_COLUMNS": "column1, column2, column3", // The values in the columns to be matched will be used for comparison
	"ZOHO_IMPORT_TYPE":      "UPDATEADD", // APPEND/ TRUNCATEADD/ UPDATEADD
	"ZOHO_ON_IMPORT_ERROR":  "ABORT", // ABORT/ SKIPROW/ SETCOLUMNEMPTY
	"ZOHO_CREATE_TABLE":     "true", // true/ false
}

resp, err := zohoService.ImportCSV(url, csvContent, params) // csvContent is a csv as string
  • Call this function in your main.go and pass in the zoho instance.
addRow(zohoService)
  • This is just an example you do not need to make an extra function to call in your main.go, just makes it a little bit cleaner.

About

zoholab is a go libary that can be used to call the zoho API.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages