JIRA REST API

Maarten de Kroon May 5, 2015

We seem to be unable to connect to the JIRA REST API at our JIRA server.

I tried both using cURL via PHP with Basic authentication and via file_get_context with a stream context to provide authentication within a HTTP header.

In all situations I was unable to receive any data. I've also tried user-posted examples that they claim work, which also return a HTTP 401 unautorized response in my case (yes, I triple checked username/password).

That makes me think, are there any special users or user requirements for using the API. Or does the API need to be activated somehow?

Regards,

Document Ready

 

 

4 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 5, 2015

Are remote calls enabled in Admin -> General config?

The REST interface will expose things with the same rights as a "real" user, so you do need to log in as someone who has access to the issues you are trying to work with.

If you meet those two criteria, then you should be able to get through, there's nothing else you need to do.

Maarten de Kroon May 5, 2015

Yes, "Accept remote API calls" is set to "ON" and I use the main admin who has access to the entire JIRA environment. Warning: file_get_contents(https://[SERVER].atlassian.net/rest/api/2/browse/DREADY-11): failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized (using same url as user in browser using file_get_contents with Authorization header) Warning: file_get_contents(https://[SERVER].atlassian.net/rest/api/2/issue/DREADY-11): failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized (fetched from examples and/or other users using file_get_contents with Authorization header) Encountered a "401 - Unauthorized" error while loading this page. Go to JIRA home (using cURL with USERPWD on either url's)

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 5, 2015

Are you running JIRA behind a web-server like Apache?

Maarten de Kroon May 5, 2015

We are running JIRA in the Atlassian cloud, not sure we can/want to tinker with that...

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 6, 2015

Ah, ok, then REST is correctly configured. You'll be getting the 401 because your authorisation is failing - you've got the right username and password, so it must be something in your code not reusing the authorisation that has been established.

0 votes
Maarten de Kroon December 14, 2016

Hi Max,

I'm not sure how we solved this but it's working now. We use an administrator login and the following cUrl request:

 

$url = 'https://xxxxx.atlassian.net/rest/api/2/search?jql=order+by+updated+DESC&expand=names&startAt=0&maxResults=5000';

$curl = curl_init();
curl_setopt($curl, CURLOPT_USERPWD, $sUsername.":".$sPassword);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);

$sIssues = curl_exec($curl);

 

That works for us. 

0 votes
Max Winther December 14, 2016

Did you solve the problem, as I have the same issue; using cloud, using a username (not email) and correct password and using basic auth through Postman or cUrl, but same results, a 401 and lot of garbage html send back to me

0 votes
Robert Massaioli _Atlassian_
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 5, 2015

Can you provide an exmaple of a JIRA rest api that you are trying to hit?

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events