简体   繁体   中英

Create a Jira Issue Using PHP and curl

I have recently started working with Jira and am trying to make a web based form on my customer client portal that will allow people to enter issues.

From my searching I have found the API examples Jira provides: https://developer.atlassian.com/jiradev/jira-apis/jira-rest-apis/jira-rest-api-tutorials/jira-rest-api-example-create-issue

However this uses something alone these lines:

curl -D- -u fred:fred -X POST --data {see below} -H 
"Content-Type: application/json" http://localhost:8090/rest/api/2/issue/

However curl is something I have never used before. I have it configured in on my server to work (did a basic test to ensure it does). But I feel like this setup is not how it works for PHP.

Online I find it says to break the curl into parts like this:

$curl = curl_init();
curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");
curl_setopt($curl, CURLOPT_URL, $url);

but I am very unsure how I would break that command into it... also unsure how I would receive the data it is supposed to return (From the sites example):

{
   "id":"39002",
   "key":"TEST-103",
    "self":"http://localhost:8090/rest/api/2/issue/TEST-103"
}

Any tips for going about creating an issue in PHP like this would be fantastic. Thanks.

There are good SDKs to work with:

https://github.com/chobie/jira-api-restclient

https://github.com/lesstif/php-jira-rest-client

Then you have a lot of function and a clean structure to work with JIRA. The second one has more function.

Login example:

use JiraRestApi\\Configuration\\ArrayConfiguration; use JiraRestApi\\Issue\\IssueService;

$iss = new IssueService(new ArrayConfiguration(
   array(
      'jiraHost' => 'https://your-jira.host.com',
      'jiraUser' => 'jira-username',
      'jiraPassword' => 'jira-password',
   )
));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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