Introduction

2018-06-28 14:05:39
Renee
484
Last edited by Renee on 2018-07-02 10:56:01

1. API introduction

API is based on HTTP. All returned data is saved as .json.


ZenTaoPHP has two mechanisms of API. One is to call from the page, the other one is to call through getModel.


2. Call from the page

When visiting a page developed in ZenTaoPHP, change .html in URL to .json, then you will get the data in .json. For example,  http://pms.zentao.net/project-task-8.html. Change it to http://pms.zentao.net/project-task-8.json, and you will get the returned data in .json. If you use GET, change the parameter of t to json, http://pms.zentao.net/?m=project&f=task&t=json.


The returned data is done with json_encode twice. See the example as shown below"


$result = file_get_contents('http://pms.zentao.net/project-task-8.json'); 
$result = json_decode($($result);
if($result->result == 'success' and md5($result->data) == $result->md5)
{
    $data = json_decode($result->data);
    print_r($data);
}
First, check whether the result in the first level is right and whether md5 signature is right, then use json_decode to data.



3. Use getModle to call

It is limited to call from the page. It might return the data you don't want, so a getModel is offered in ZenTaoPHP to call.


First, add the privilege to the account that you will want it to call by the getModel. Then use getModel in API to get the open method of the model in any module.


Module name, method name and the parameters of the method are required in getModel. Use commas to separate each parameter. For example, key1=value1,key2=value2.


Take getUserBugPairs() in the module of Bug in ZenTao as an example.

  • GET: ?m=api&f=getModel&module=bug&methodName=getUserBugPairs&params=account=$account
  • PATH_INFO: api-getmodel-bug-getUserBugPairs-account=$account.json


Note

Use getModel to call is ONLY applied to ZenTao. Zsite or Zdoo is not supported yet.



If any questions, leave a message below. We will reply ASAP. Or shoot us an email at Renee@cnezsoft.com or liujun@cnezsoft.com.




Write a Comment
Comment will be posted once reviewed.