繁体   English   中英

通过SOAP API和PHP创建JIRA问题

[英]Create JIRA issue via SOAP API and PHP

我无法通过PHP中的SOAP API创建问题。 我尝试了这个:

$soapClient = new SoapClient("http://jira:9090/rpc/soap/jirasoapservice-v2?wsdl");
$token = $soapClient->login('user', 'pass');
$issue=array(
    'type'=>3,
    'priority'=>3,
    'project'=>'XXX',
    'duedate'=>time(),
    'components'=>'',
    'versions'=>'',
    'fixVersions'=>'',
    'assignee'=>'user1',
    'reporter'=>'user1',
    'environment'=>'',
    'description'=>'test',
    'summary'=>'test',
    'timetracking'=>'',
    'attachment'=>'',
    'labels'=>''
);
$soapClient->createIssue($token, $issue);

但是,当我运行此脚本时,不会在JIRA中创建新问题。 有人可以帮我解决这个问题吗?

确保:

  • 项目名称正确
  • 存在问题类型3,并且包含所有这些字段
  • user1 (在“问题”字段中)具有该项目的受让人和报告者的权限(尝试手动进行)
  • user (通过身份验证)有权在此项目中创建新问题(与用户手动登录并尝试创建问题)

duedate'=>time()对我来说工作正常。 实际上,在Jira 4.4.4下,我接受了您的代码,更改了项目,报告人和被许可人的名称,并且对我有用。

奇怪的是,如果出现问题,您应该得到一个错误,那么您如何尝试执行php文件? 尝试手动运行它以检查错误。 为此,请使用以下标头创建一个PHP文件:

#!/usr/bin/php

赋予它运行权限chmod +x myscript.php并执行./myscript.php 如果从Web服务器运行它,请检查/var/log/httpd/error_log是否有错误。 确保已安装SOAP:

[root@localhost]# cat /etc/php.d/soap.ini
; Enable soap extension module
extension=soap.so

如果发现任何错误,请更新问题。

您的问题查询必须是一个对象

$issueQuery = new stdClass;

您所有的字段都必须在数组中

$customFields = array();

您的自定义字段必须是一个对象

$fieldOBJ = new stdClass;
$fieldOBJ->customfieldId = 'customfield_10237';
$fieldOBJ->key = '';
$fieldOBJ->values = array(utf8_encode($value));

将其添加到数组

$customFields[] = $fieldOBJ;

将自定义字段添加到问题查询(和其他主要字段)

$issueQuery->customFieldValues = $customFields;

创建问题($ token是您的连接)

$issueCreated = $soapClient->createIssue($token, $demande);

而已! $ issueCreated将是返回的问题密钥

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM