架好 Mantis 後,預設是有開啟 SOAP API 的,可以瀏覽 /mantis/api/soap/mantisconnect.php?wsdl 試試,應該會看到 SOAP API 的使用列表跟使用方式。
使用上需要指定 user, password 跟 project id,目前沒找到一口氣列出所有 project 的方法?倒是可以用 project name 找 project id,而發一則 issue 必須要有的資訊:project id, category, summary, description,連續動作:
<?php
$c = new SoapClient('http://YourMantisServerIP/mantis/api/soap/mantisconnect.php?wsdl');
$user = 'report_account';
$pass = 'report_password';
$project_name = 'ProjectName';
$issue_summary = 'Report title';
$issue_description = 'Report body';
$issus_category = 'iOS';
$project_id = $c->mc_project_get_id_from_name($user, $pass, $project_name);
if ($project_id == 0) {
echo "[ERROR] Project ID Not Found: [$project_name]\n";
exit;
}
$categories = $c->mc_project_get_categories($user, $pass, $project_id);
print_r($categories);
//$custom_fields = $c->mc_project_get_custom_fields($user, $pass, $project_id);
//print_r($custom_fields);
$issue_data = array(
'project' => array(
'id' => $project_id
),
'category' => $issus_category,
'summary' => $issue_summary,
'description' => $issue_description
);
$issus_id = $c->mc_issue_add($user, $pass, $issue_data);
echo "Issue ID: $issus_id\n";
成功的話,就會看到最後印出的 Issue ID。
對於 SOAP 的簡介可以參考:如何透過PHP、SOAP 及 WSDL撰寫Web Service
沒有留言:
張貼留言