使用jira SOAP API获取jira问题的customfield值



我想使用SOAP API获取特定JIRA问题的所有自定义字段的值。我有一个名为"阶段">的自定义字段,其值为Decision Pending,用于JIRA问题JIRA-123

我正在使用JIRA 5.1.3

我能够使用SOAP API获得JIRA问题的所有属性,除了上面问题的自定义字段的值。

我尝试了以下代码,但无法在我的代码中使用ComponentManager

IssueManager issueManager = ComponentManager.getInstance().getIssueManager();
CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager();
Issue issue = issueManager.getIssueObject("JIRA-123");
CustomField customField = customFieldManager.getCustomFieldObjectByName("Phase");
Object customFieldValue = issue.getCustomFieldValue(customField);

如果有人能提供正确的方法,我将不胜感激。

SOAP API已被5.1.3弃用。我建议您使用REST API,它更易于使用和实现。

什么是REST?:请阅读此处。基本思想是将HTTP请求类型绑定到操作,这一点很明显——请查看此表以获得快速磨合。

Jira有一个强大的REST API,您可以使用它。这是当前版本的主要文档。

在一些高级步骤中,您需要做什么?:

  1. 使用JIRA实例设置某种类型的身份验证。是吧:

    • Baisc-示例
    • OAuth-示例
  2. 通过API获取所有字段的列表:

    /rest/api/2/field' [method returns a list of all fields][6] - both System and Custom. Then when you identify the exact field use/rest/api/2/customFieldOption/{id}`以获得自定义字段选项的完整
    表示。

我建议您使用Chrome REST控制台等工具,或任何类似的工具,您可以轻松地进行请求,以了解API。额外的好处是,如果您是通过同一浏览器登录的,则无需设置身份验证。不过,您的用户将需要完全的管理员访问权限。

这是所有JIRA REST API文档的根目录。看看吧。

如果你在PHP中这样做,我个人建议你使用某种库。我用过Guzzle(在CakePHP环境中)完成了这项任务,结果非常好。

我不确定如何使用soap API,下面是通过PHP-soap:使用它的示例

#!/usr/bin/php -q
<?php
$soapClient = new SoapClient("https://jira.com/rpc/soap/jirasoapservice-v2?wsdl");
$token = $soapClient->login('user', 'password');
$myIssue = $soapClient->getIssue($token,"TES-13");
print_r($myIssue); // all of the issue details
print_r($myIssue->customFieldValues); // get all custom fields
foreach ($myIssue->customFieldValues as $customFieldValue) {
// search for the right custom field
if ($customFieldValue->customfieldId == 'customfield_10402') {
echo $customFieldValue->values[0];
die();
}
}
?>

如果您想使用任何其他API,请查看JIRA远程API参考。

关于REST和SOAP API的备注——引用Jira网站上的SOAP API"支持但没有未来的开发"。Rest API仍然有点新,有些事情你还不能用Rest API做(例如),可以用SOAP API轻松完成。

最新更新