0

Creating a JIRA issue with PHP using cURL

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
$path = 'c:\server\public_html';
$base_url = 'http://jira';
 
//Required variables
$atlassian_user = '';
$atlassian_password = ''; 
$jira_pid = '10001';
$jira_issuetype = '1';
$jira_summary = urlencode("Summary");
$jira_description = urlencode("Description");
$jira_reporter = '';
$jira_priority = '4';
 
//Optional variables
$jira_assignee = '';
 
//Initialize a cURL session
$curl = curl_init();
 
//The URL to fetch
curl_setopt($curl, CURLOPT_URL, $base_url . '/login.jsp?os_username=' . $atlassian_user . '&os_password=' . $atlassian_password . '&os_cookie=true');
 
//Do a regular HTTP POST
curl_setopt($curl, CURLOPT_POST, true);
 
//Store cookie data in cookiejar.txt
curl_setopt($curl, CURLOPT_COOKIEJAR, "$path\cookiejar.txt");
 
//Do not follow any "Location: " header that the server sends as part of the HTTP header
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false);
 
//Exclude the body from the output and set the request method to HEAD
curl_setopt($curl, CURLOPT_NOBODY, true);
 
//Execute cURL session
curl_exec($curl);
 
//Include the body from the output
curl_setopt($curl, CURLOPT_NOBODY, false);
 
//Set HTTP header fields to pass along
curl_setopt($curl, CURLOPT_HTTPHEADER, array("X-Atlassian-Token: no-check"));
 
//The URL to fetch
curl_setopt($curl, CURLOPT_URL, $base_url . "/secure/CreateIssueDetails.jspa?pid=$jira_pid&issuetype=$jira_issuetype&summary=$jira_summary&description=$jira_description&assignee=$jira_assignee&reporter=$jira_reporter");
 
//Execute cURL session
curl_exec($curl);
 
//Close cURL session
curl_close($curl);

Norbert Krupa

Technical Consultant

Leave a Reply

Your email address will not be published.