使用rest api更新jira问题。不肥皂 [英] Updating a jira issue with the rest api. NOT soap

查看:358
本文介绍了使用rest api更新jira问题。不肥皂的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的php函数更新jira的问题是这样的。我有硬编码的问题id.it生成一个错误在 if(property_exists($ result,'errors'))。说的参数不是对象。

 函数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'=>'通过REST测试,
'description'=&
'issuetype'=> array('name'=>'Task')
))
);

$ result = create_issue($ new_issue);
if(property_exists($ result,'errors')){
echo错误创建问题:\\\
;
var_dump($ result);
}
}

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

解决方案

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



更改

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

到:

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

和:

 code> $ new_issue = array(
'update'=> array(
'fields'=> array(
'project'=& >'DOTNET'),
'summary'=>'通过REST测试',
'description'=>'问题描述在这里。',
'issuetype' > array('name'=>'Task')
))
);

到:

 code> $ new_issue = array(
'fields'=> array(
'project'=> array('key'=>'DOTNET'),
' summary'=>'通过REST测试,
'description'=>'问题描述在这里。',
'issuetype'=> array('name'=>' ')

);

最后更改:

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

到您的实际地址,以及写 code>而不是 latest ,即:

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



尝试更改:

  CURLOPT_POST => 1,

到:

  CURL_POST => true,
CURLOPT_VERBOSE => 1,

btw,你的jira服务器在哪里?你不是说它是托管吗? localhost:8080 将仅在Jira安装在本地时工作。如果是,请尝试使用浏览器打开它 http:// localhost:8084 / rest / api / 2 / issue /



EDIT 2



确保允许远程API调用



网址应该指向即将到达的网址。



< -be更新的问题,即:

  http:// localhost / rest / api / 2 / issue / TEST- b $ b  

,数据应与以前相同,意味着:

  $ new_issue = array(
'fields'=> array(
'project'=> array('key'=> DOTNET'),
'summary'=>'通过REST测试',
'description'=>'问题描述在这里。',
'issuetype'=> array ('name'=>'Task')

);

,就像您在尝试创建问题时写的一样。您可以在此处找到一些简单的示例如何这样做。



编辑3



右吉拉地址?请尝试重新打开浏览器并访问网址,并将其与此示例。如果该网页不显示,您必须与 Jira的支持人员联系,并询问他们如何无法访问托管的Jira远程API。


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')). 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, i.e.:

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? didn't you say it was hosted? localhost:8080 will work only if Jira is installed locally. If so, try opening it using a browser http://localhost:8084/rest/api/2/issue/

EDIT 2

Make sure the Allow Remote API Calls is turned ON under Administration > General Configuration.

to update an issue:

the URL should point to the soon-to-be-updated issue, i.e.:

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

Are you sure you have the right jira address? try again opening a browser and going to the URL and compare it to this example. 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.

这篇关于使用rest api更新jira问题。不肥皂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆