1. Configuration parameters
The ZenTao PHP-SDK was added to the zentao framework directory after ZenTao open source version 12.0.1, and the ZenTao PHP-SDK file is located under zentao project directory/sdk/php/. Before using the SDK (zentao.php) file, you need to fill in some necessary configuration information in the referenced Zentao SDK file. The domain name of the ZenTao installation and deployment, the ZenTao user account, the ZenTao user password, and the parameter request method of the ZenTao configuration.
const ztUrl = 'http://zentao.*****.com'; // domain that ZenTao is installed
const ztAccount = 'admin'; // ZenTao login username
const ztPassword = '123456'; // ZenTao login password
const ztAccessMode = 'PATH_INFO'; // ZenTao request method [ GET | PATH_INFO ]
2. List of available APIs for ZenTao SDK
- Get a list of departments
- Batch add departments
- Get a list of users
- Add individual user optional information
- Add a single user
- Get a list of products
- Add a single product with optional information
- Add a single product
- Get a list of projects
- Add a single item with optional information
- Add a single project
- Get a list of tasks
- Add a single task with optional information
- Add a single task
- Complete a single task optional information
- Complete a single task
- Get a list of bugs
- Add single bug optional information
- Add a single bug
- Resolve a single bug optional information
- Resolve a single bug
3. Instructions and examples
3.1 Instructions
Before use the ZenTao SDK, make sure that the configuration is correct, and that the login account has the right permissions and that the password is not weak. All requested API results are returned in JSON format. You can decide whether the request was successful based on the status in the request result. If the request fails, APIs will give corresponding prompts. In requesting the API, take [Get Department Lists] as an example. $params contains the request parameters that can be passed. It can be an empty array. This parameter can be omitted when required parameters are not passed in the parameter. $extraFields is a customized field, which can be returned according to the required results. The customized fields are not limited to the fields as showed in the example, and it cannot be passed.
3.2 Examples
Below is an example using the zentaoPHP framework. Place the SDK files in tools/zentao/. ThinkPHP, Laravel, and other mainstream frameworks can be placed in the framework directory according to your needs, and the directory should follow the ZenTao framework specification as much as possible.
/**
* Get a department list
*
* @access public
* @return void
*/
public function getDeptList()
{
include_once('../../tools/zentao/zentao.php');
$zentao = new zentao(); // Initiate the class. If failed, change it to "\new zentao();"
$params = array('deptID' => 1); // the parameter requested
$extraFields = array('title', 'deptID', 'parentDepts', 'sons', 'tree'); // fields returned
$result = $zentao->getDeptList($params, $extraFields); // revoke SDK
echo $result;
}
4. FAQ
Q: An error message "Trying to get property of non-object" appears when calling a method in the ZenTao SDK class.
A: Print the result of the request ($result) in the SDK and check the returned information for the reason.
Solution 1: Change the password settings.
Log in ZenTao and select Admin-> Security-> Password settings. Turn off Password Strength, Force to change weak password, and Force to change password after first login.
<html><meta charset='utf-8'/>
<style>body{background:white}</style>
<script>self.location='/index.php?m=my&f=changepassword&t=json';</script>
Solution 2: Assign the user permission.
Log in ZenTao and select Admin-> Privilege to set the privileges for users.
<html><meta charset='utf-8'/>
<style>body{background:white}</style>
<script>self.location='/index.php?m=user&f=deny&t=json&module=dept&method=browse';</script>
Solution 3: Missing parameters.
Find the relavant method in the API list and check whether the passed parameters match that in the document list.
Q: An error message "Fatal error: Uncaught Error: Call to undefined function curl_init()" appears when calling a method in the ZenTao SDK class.
A: The reason for this error is that PHP is missing the curl extension, so install this PHP extension and it will be back in business.