It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Jira REST API 403 Forbidden Basic Authentication with PHP

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
DPK J Community Leader Dec 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.

@Fabian Keketzdo 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/

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you