php – 使用其余的api更新jira问题.不是肥皂

我更新jira问题的php函数就像this.i硬编码问题id.it在if(property_exists($result,’errors’))中生成错误.说参数不是一个对象.

function post_to($resource, $data) {
$jdata = json_encode($data);
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_POST => 1,
CURLOPT_URL => JIRA_URL . '/rest/api/latest/' . $resource,
CURLOPT_USERPWD => USERNAME . ':' . PASSWORD,
CURLOPT_POSTFIELDS => $jdata,
CURLOPT_HTTPHEADER => array('Content-type: application/json'),
CURLOPT_RETURNTRANSFER => true
));
$result = curl_exec($ch);
curl_close($ch);
return json_decode($result);
}

function create_issue($issue) {
return post_to('issue/10224/editmeta', $issue);
}

$new_issue = array(
    'update' =>array(
        'fields' => array(
            'project' => array('key' => 'DOTNET'),
            'summary' => 'Test via REST',
            'description' => 'Description of issue goes here.',
            'issuetype' => array('name' => 'Task')
            ))
);

$result = create_issue($new_issue);
if (property_exists($result, 'errors')) {
echo "Error(s) creating issue:\n";
var_dump($result);
                }
            }

我在这做错了什么?请回答.

解决方法:

不太确定,让我们尝试一下:

更改

CURLOPT_HTTPHEADER => array('Content-type: application/json'),

至:

CURLOPT_HTTPHEADER => array(
    'Accept: application/json',
    'Content-Type: application/json'
);

和:

$new_issue = array(
    'update' =>array(
        'fields' => array(
            'project' => array('key' => 'DOTNET'),
            'summary' => 'Test via REST',
            'description' => 'Description of issue goes here.',
            'issuetype' => array('name' => 'Task')
            ))
);

至:

$new_issue = array(
    'fields' => array(
        'project' => array('key' => 'DOTNET'),
        'summary' => 'Test via REST',
        'description' => 'Description of issue goes here.',
        'issuetype' => array('name' => 'Task')
     )
);

最后,改变:

CURLOPT_URL => JIRA_URL . '/rest/api/latest/' . $resource,

到你的真实地址,以及写2而不是最新的,即:

CURLOPT_URL=>'http://localhost/rest/api/2/issue/',

试试这个,让我知道它是怎么回事,祝你好运!

编辑

尝试改变:

CURLOPT_POST => 1,

至:

CURL_POST=>true,
CURLOPT_VERBOSE=>1,

顺便问一下,你的jira服务器在哪里?你不是说它被托管了吗? localhost:8080仅在本地安装Jira时才有效.如果是这样,请尝试使用浏览器http:// localhost:8084 / rest / api / 2 / issue /打开它

编辑2

确保在“管理”>下打开“允许远程API调用”.一般配置.

更新问题:

URL应指向即将更新的问题,即:

http://localhost/rest/api/2/issue/TEST-31

并且数据应与之前相同,这意味着:

$new_issue = array(
    'fields' => array(
        'project' => array('key' => 'DOTNET'),
        'summary' => 'Test via REST',
        'description' => 'Description of issue goes here.',
        'issuetype' => array('name' => 'Task')
     )
);

正如您在尝试创建问题时所写的那样.你可以找到here一些如何做的简单例子.

编辑3

你确定你有正确的jira地址吗?再次尝试打开浏览器并转到URL并将其与this example进行比较.如果页面未显示,则必须联系Jira’s support并询问他们如何才能访问托管的Jira远程API.

上一篇:如何使用rest api(java)在jira中创建问题?


下一篇:Jira - 如何创建项目?