简体   繁体   English

使用其余api更新jira问题。 不是肥皂

[英]Updating a jira issue with the rest api. NOT soap

my php function to update jira issue is like this.i have hardcoded the issue id.it generates an error in if (property_exists($result, 'errors')) . 我的更新jira问题的php函数是这样的。我已经对问题ID进行了硬编码。它在if (property_exists($result, 'errors')) saying parameter is not an object. 说参数不是对象。

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);
                }
            }

what am i doing wrong here? 我在这里做错了什么? please answer. 请回答。

Not really sure, let's try some thing: 不太确定,让我们尝试一下:

change 更改

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

to: 至:

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

and: 和:

$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')
            ))
);

to: 至:

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

lastly, change: 最后,更改:

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

to your real address, as well as writing 2 instead of latest , ie: 到您的真实地址,以及写2而不是latest ,即:

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

try this, and let me know how it's goes, good luck! 试试看,让我知道它的进展,祝你好运!

EDIT 编辑

try changing: 尝试更改:

CURLOPT_POST => 1,

to: 至:

CURL_POST=>true,
CURLOPT_VERBOSE=>1,

btw, where is your jira server? 顺便说一句,您的jira服务器在哪里? didn't you say it was hosted? 您不是说托管吗? localhost:8080 will work only if Jira is installed locally. 只有在本地安装了Jira时, localhost:8080才能工作。 If so, try opening it using a browser http://localhost:8084/rest/api/2/issue/ 如果是这样,请尝试使用浏览器http://localhost:8084/rest/api/2/issue/打开它

EDIT 2 编辑2

Make sure the Allow Remote API Calls is turned ON under Administration > General Configuration. 确保在“管理”>“常规配置”下Allow Remote API Calls

to update an issue: 更新问题:

the URL should point to the soon-to-be-updated issue, ie: 该URL应指向即将更新的问题,即:

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

and the data should be the same as before, meaning: 数据应与以前相同,即:

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

just as you wrote when you tried to create an issue. 就像您尝试创建问题时所写的一样。 you can find here some simple example of how to do so. 您可以在此处找到一些简单的示例。

EDIT 3 编辑3

Are you sure you have the right jira address? 您确定您的jira地址正确吗? try again opening a browser and going to the URL and compare it to this example . 再次尝试打开浏览器并转到URL,然后将其与本示例进行比较。 If the page won't show, you will have to contact Jira's support and ask them how come you can't access the hosted Jira remote API. 如果该页面无法显示,则您必须联系Jira的支持人员,并询问他们为什么无法访问托管的Jira远程API。

editmeta should be used only to OBTAIN meta data from an issue. editmeta仅应用于从问题中获取OBTAIN元数据。

To update an issue you must use the issue method. 要更新问题,您必须使用问题方法。

You can check the Jira API details here: https://docs.atlassian.com/jira/REST/cloud/#api/2/ 您可以在此处查看Jira API详细信息: https : //docs.atlassian.com/jira/REST/cloud/#api/2/

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

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