Introduction

2018-06-28 14:40:09
Renee
9194
Last edited by tengfei on 2019-01-08 09:57:12

1. API introduction

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


ZenTaoPHP has two mechanisms of API. 



  • call on the page, and
  • call through getModel.



2. Call on 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 on 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.






Write a Comment
Comment will be posted after it is reviewed.