Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

API unauthorized 401 with php

Davor Radic
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 14, 2018

I want to user Jira API.

Here is what I did:
first I searched for some php api frameworks and I found one:
https://github.com/lesstif/php-jira-rest-client

Then I installed on my localhost on mac jira (7.9.2)

All works fine and I made one project and it is called TEST
if I loggin and go in the browser with this url: http://localhost:8080/rest/api/2/project/TEST works perfect, I get the json back.

Ok then I go and try to do it with php framework https://github.com/lesstif/php-jira-rest-client and nothing al the time access denied.

Then I tried to go with cloud version and still same authorized 401.

I made issue on they github account and here is the link, maybe you will know the answer:
https://github.com/lesstif/php-jira-rest-client/issues/153

It is frustrating that I get no access :( so any idea would be helpfull

thank you all

1 answer

0 votes
Arun_Thundyill_Saseendran
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.
May 14, 2018

Please post your code snippet and we will be able to help! 

Davor Radic
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 15, 2018
library that is used is: https://github.com/lesstif/php-jira-rest-client

class
Jira extends Controller
{
private $jiraHost;
private $jiraUsername;
private $jiraPassword;
private $config;

/**
* @Route("/", name="devops_jira")
*/
public function index()
{
$this->jira_auth();
var_dump($this->config);
try {
$proj = new ProjectService($this->config);
$prjs = $proj->getAllProjects();
var_dump($prjs);
foreach ($prjs as $p) {
echo sprintf("Project Key:%s, Id:%s, Name:%s, projectCategory: %s\n",
$p->key, $p->id, $p->name, $p->projectCategory['name']
);
}
} catch (JiraException $e) {
print("Error Occured! " . $e->getMessage());
}

return new Response('');
}

public function jira_auth()
{
$user = $this->getUser();
$this->jiraHost = $user->getJiraHost();
$this->jiraUsername = $user->getJiraUsername();
$this->jiraPassword = $user->getJiraPassword();

$this->config = new ArrayConfiguration(
array(
'jiraHost' => 'https://username.atlassian.net',//$this->jiraHost,
// for basic authorization:
'jiraUser' => $this->jiraUsername,
'jiraPassword' => 'api token',//$this->jiraPassword,
// to enable session cookie authorization (with basic authorization only)
///'cookieAuthEnabled' => true,
'jiraLogFile' => 'DEBUG',
//'curlOptSslVerifyHost' => true
)
);

}
}

Suggest an answer

Log in or Sign up to answer