Jira REST API 403 Forbidden Basic Authentication with PHP

kardon December 13, 2019

Hello everyone,

I'm new to Jira REST API so I have a Jira running on localhost, just to get used to it. Right now I'm just tryring to authenticate. The problem ist, that I get a 403. This is my code:

 

$username = 'username';
$password = 'api token';
$curl_handle=curl_init();
curl_setopt($curl_handle, CURLOPT_URL,'http://localhost:8080/rest/api/2/user?username=username');
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_handle, CURLOPT_USERPWD, "$username:$password");
curl_setopt($curl_handle, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);

$query = curl_exec($curl_handle);
curl_close($curl_handle);
echo $query;

2 answers

0 votes
Jakub Sławiński
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 13, 2019

@kardondo you want to use api tokens with Jira Server? Api tokens are only for Jira Cloud.

 

You can check more here: https://developer.atlassian.com/server/jira/platform/security-overview/

0 votes
DPKJ
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 13, 2019
$ch = curl_init();

curl_setopt_array($ch, array(
  CURLOPT_URL => JIRA_URL . '/rest/api/2/user?username=' . $USER,
  CURLOPT_USERPWD => $USERNAME . ':' . $PASSWORD,
CURLOPT_HTTPHEADER => array('Content-type: application/json'), CURLOPT_RETURNTRANSFER => true ));
$result = curl_exec($ch); curl_close($ch); echo json_decode($result);

 

Can you above code a trial? If this works, and are you admin on your instance, i.e. have permission to read users information.

Suggest an answer

Log in or Sign up to answer