Wallogit.com
2017 © Pedro Peláez
ZohoReports PHP SDK
This repo is for an outdated version of Zoho API., (*1)
This is a PHP SDK that provides integration with Zoho Reports through their API., (*2)
The only requirement is PHP >=5.5.0, (*3)
The raccomended way is to install ZohoReports-SDK is through Composer., (*4)
Please refer to Getting Started on how to download and install Composer., (*5)
After you have downloaded/installed Composer, run, (*6)
composer.phar require freemancontingent/zohoreports-sdk
or add it in your composer.json, (*7)
{
"require": {
"freemancontingent/zohoreports-sdk": "dev-master"
}
}
You should have a valid Zoho login email address to use the API. If you do not have one, please Sign up into Zoho Reports and create a login., (*8)
You must provide your Zoho email, your Database name (the database in Zoho Reports), and your Zoho Authtoken, (*9)
$zoho = new ZohoReports\ZohoReports('my-zoho-email', 'my-db', 'my-authtoken');
The import is highly customizable, it supports almost all the different configurations provided by the Zoho Reports API., (*10)
In most of the cases this will suits your need., (*11)
$res = $zoho->import('somefile.csv', 'My-Table');
The first parameter is the full path to your csv file, the second parameter is the table in your Zoho Reports Database where your data will be imported., (*12)
This will truncate My-Table in your Zoho Reports Database and import all the data from somefile.csv. If My-Table doesn't exists, it will be created., (*13)
You can pass parameters (an array of parameters) to the import function that will override the default settings., (*14)
$res = $zoho->import('somefile.csv', 'My-Table', ['param1' => 'my-value', ...]);
| Param Name | Description | Values | Default |
|---|---|---|---|
| format [string] | Format of the file to be imported. | CSV, JSON | CSV |
| create [string] | This will create the table if doesn't exist (if 'true'). | 'true', 'false' | 'true' |
| type [string] | Define the import type | APPEND, TRUNCATEADD, UPDATEADD | TRUNCATEADD |
| dateFormat [string] | Format of the dates | 'yyyy-MM-dd HH:mm:ss' | |
| autoIdentify [string] | Specify if auto identify the CSV format | 'true', 'false' | 'true' |
| skip [integer] | The number of columns to skip from the top of the CSV file | 0 | |
| onError [string] | Define the action to be taken in case there is an error during the import | 'ABORT', 'SKIPROW', 'SETCOLUMNEMPTY' | 'SETCOLUMNEMPTY' |
When defining your own parameters, in some case you need to provide more informations., (*15)
type is 'UPDATEADD', you must provide a pk param, that defines your primary key, or your matching column used for comparisonformat is CSV and autoIdentify is 'false', you must provide:
csvCommentChar, the comment char used in your csv filecsvDelimeter, the values delimeter, that can be set to:
0 for COMMA1 for TAB2 for SEMICOLON3 for SPACEcsvQuoted, the text qualifier, that can be set to:
0 for none1 for SINGLE QUOTE2 for DOUBLE QUOTEThere are two type of exception:, (*16)
$param['type'] = 'UPDATEADD' and you haven't provided $param['pk']
Include the ZohoReports.php file in your project, or if you prefer using an autoloader have a look at test.php, (*17)
$zoho = new ZohoReports\ZohoReports('my-zoho-email', 'my-db', 'my-authtoken');
try {
$res = $zoho->import('path/to/somefile.csv', 'My-Table');
} catch(Exception $e) {
echo $e->getMessage();
exit();
}
$zoho = new ZohoReports\ZohoReports('my-zoho-email', 'my-db', 'my-authtoken');
try {
$res = $zoho->import('path/to/somefile.csv', 'My-Table', [
'type' => 'UPDATEADD',
'pk' => 'id'
]);
} catch(Exception $e) {
echo $e->getMessage();
exit();
}
$zoho = new ZohoReports\ZohoReports('my-zoho-email', 'my-db', 'my-authtoken');
$myFilesToImport = [
'path/to/movies.csv' => 'movie_id',
'path/to/actors.csv' => 'actor_id',
'path/to/genres.csv' => 'genre_id'
];
foreach ($myFilesToImport as $path => $pk) {
try {
$res = $zoho->import($path, basename($path), [
'type' => 'UPDATEADD',
'pk' => $pk
]);
} catch(ZohoReport\InvalidFileException $e) {
myLogger("File {$path} not imported. Exception: {$e->getMessage()}");
continue;
} catch(ZohoReport\InvalidParamsException $e) {
myLogger("Wrong parameter for {$path}. {$e->getMessage()}");
exit();
}
}