lesstif / php-jira-rest-client

PHP classes interact Jira with the REST API.
Other
510 stars 263 forks source link

getAllProjects returning empty #406

Closed wimg-bstuckey closed 2 years ago

wimg-bstuckey commented 2 years ago

I am trying to run just the basic example off the main github page to get all project to test but it is returning empty

<?php
require 'vendor/autoload.php';

use JiraRestApi\Project\ProjectService;
use JiraRestApi\JiraException;

try {
    $proj = new ProjectService();

    $prjs = $proj->getAllProjects();

    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 (JiraRestApi\JiraException $e) {
        print("Error Occured! " . $e->getMessage());
}

?>

this is my .env

JIRA_HOST="https://***.atlassian.net"
TOKEN_BASED_AUTH=true
PERSONAL_ACCESS_TOKEN="***"
JIRA_REST_API_V3=true

JIRA_LOG_FILE="jira-rest-client.log"
JIRA_LOG_LEVEL="DEBUG"
JIRA_LOG_ENABLED=true

I did some searching on issues before posting this and found a suggestion to add the log stuff to the .env file i did that and the output to the log was [2022-01-21T22:05:54.875075+00:00] JiraClient.DEBUG: Curl exec=https://***.atlassian.net/rest/api/3/project? [] [] please note i starred out our URL BUT when I go to the URL manually in the browser it pops up all the projects so I am not sure why when using the SDK its not returning all the projects?

UPDATE: I also just noticed in JIRA it says that api key i made has not been accessed even though I've ran this script about 5 or 10 times now. BUT obviously the .env is being used cause im getting logs 🤨

wimg-bstuckey commented 2 years ago

I just spit out the headers it looks like its building for the curl call idk if this will help

array(4) {
  [0]=>
  string(11) "Accept: */*"
  [1]=>
  string(30) "Content-Type: application/json"
  [2]=>
  string(27) "X-Atlassian-Token: no-check"
  [3]=>
  string(46) "Authorization: Bearer ***"
}
wimg-bstuckey commented 2 years ago

I ran curl verbose flag in .env and got this

* Connected to ***.atlassian.net (***) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*  CAfile: /etc/pki/tls/certs/ca-bundle.crt
*  CApath: none
* SSL connection using TLSv1.2 / ECDHE-ECDSA-AES128-GCM-SHA256
* ALPN, server accepted to use h2
* Server certificate:
*  subject: C=US; ST=California; L=San Francisco; O=Atlassian, Inc.; CN=*.atlassian.net
*  start date: Dec  7 00:00:00 2021 GMT
*  expire date: Dec  6 23:59:59 2022 GMT
*  issuer: C=US; O=DigiCert Inc; CN=DigiCert TLS Hybrid ECC SHA384 2020 CA1
*  SSL certificate verify ok.
* Using HTTP2, server supports multiplexing
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x55d79e664f80)
> GET /rest/api/3/project? HTTP/2
Host: ***
accept-encoding: deflate, gzip
accept: */*
content-type: application/json
x-atlassian-token: no-check
authorization: Bearer ***

* Connection state changed (MAX_CONCURRENT_STREAMS == 200)!
< HTTP/2 200
< server: AtlassianProxy/1.19.3.1
< vary: Accept-Encoding
< cache-control: no-cache, no-store, no-transform
< content-type: application/json;charset=UTF-8
< content-encoding: gzip
< strict-transport-security: max-age=315360000; includeSubDomains; preload
< date: Fri, 21 Jan 2022 22:44:07 GMT
< atl-traceid: 6b3b35776ec79327
< x-arequestid: e3e653a0-73c6-4de0-906e-beb88a7e43d7
< x-xss-protection: 1; mode=block
< timing-allow-origin: *
< x-envoy-upstream-service-time: 47
< x-content-type-options: nosniff
< set-cookie: atlassian.xsrf.token=BL7U-ZJ0S-NGYP-ZXHB_009ec5736026d3ddc80c014e78affbc8d5455c52_lout; path=/; SameSite=None; Secure
< expect-ct: report-uri="https://web-security-reports.services.atlassian.com/expect-ct-report/global-proxy", enforce, max-age=86400
<
* Connection #0 to host *** left intact
lesstif commented 2 years ago

hi @wimg-bstuckey

thank you for reaching out to me. I've been getting the same result on Jira cloud, but Server/DC instance is ok.

so it needs digging into analysis, but I can start with next week.

could you run other samples, please?

niclashoyer commented 2 years ago

@lesstif @wimg-bstuckey for me this is working with cloud instance if one just uses the API-Token as password, e.g.:

JIRA_HOST="https://jira.atlassian.net"
JIRA_USER="username"
JIRA_PASS="apitoken"
TOKEN_BASED_AUTH=false
wimg-bstuckey commented 2 years ago

@lesstif @wimg-bstuckey for me this is working with cloud instance if one just uses the API-Token as password, e.g.:

JIRA_HOST="https://jira.atlassian.net"
JIRA_USER="username"
JIRA_PASS="apitoken"
TOKEN_BASED_AUTH=false

was hoping this would work but i get this when i run in browser

Error Occured! CURL HTTP Request Failed: Status Code : 404, URL:https://jira.atlassian.net/rest/api/3/project?
Error Message : Page unavailable
Your Atlassian Cloud site is currently unavailable.

we log in with Google so I'm not 100% on what my username should be I just used my email address

wimg-bstuckey commented 2 years ago

hi @wimg-bstuckey

thank you for reaching out to me. I've been getting the same result on Jira cloud, but Server/DC instance is ok.

so it needs digging into analysis, but I can start with next week.

could you run other samples, please?

sure are you meaning like just run different API calls like besides get all projects?

wimg-bstuckey commented 2 years ago

@lesstif @wimg-bstuckey for me this is working with cloud instance if one just uses the API-Token as password, e.g.:

JIRA_HOST="https://jira.atlassian.net"
JIRA_USER="username"
JIRA_PASS="apitoken"
TOKEN_BASED_AUTH=false

actually im an idiot this worked I literally put JIRA_HOST="https://jira.atlassian.net" and it should have been JIRA_HOST="our-custom-url"

niclashoyer commented 2 years ago

we log in with Google so I'm not 100% on what my username should be I just used my email address

I also used Google-Auth and I used my mail address as user like this:

curl -v -u 'niclas@example.com:your_api_key_here' https://yoursitename.atlassian.net/rest/api/3/project

But you may need to replace the sitename yoursitename to get it to work.