Retrieve a List of Issues for a Project

Coverity on Polaris

Version
latest
You can use the Coverity on Polaris API to retrieve a list of issues for a project with the following cURL, Python, and Java API examples.

Prerequisite

Create a JWT. See Coverity on Polaris API Authentication.
Note: About these examples:
  • Make sure to replace the URL with your specific instance of Polaris. (Every organization has a unique URL.)
  • Replace {JWT} with your API token.

cURL: Retrieve a List of Issues for a Project
  1. Get a project by name with included branches, and extract a project ID and branch.
    $ curl -X GET \"https://subdomain.cop.blackduck.com/api/auth/v1/organizations&page[limit]=1&page[offset]=0" \
          -H 'Accept: application/vnd.api+json' \
          -H 'Authorization: Bearer {JWT}'
  2. Use the project and branch IDs to get the list of open issues.
    $ curl -X GET \
    "https://subdomain.cop.blackduck.com/api/query/v1/issues?
    project-id={{project-ID}}&branch-id={{branch UUID}}&filter[issue][status]
    [$eq]=opened&include[issue][]=severity&page[limit]=25&page[offset]=0" \
    -H 'Accept: application/vnd.api+json' \
    -H 'Authorization: Bearer {JWT}'
    

Python: Retrieve a List of Issues for a Project


  
  import json
  from http.client import HTTPSConnection, HTTPResponse
  
  polaris = HTTPSConnection('subdomain.cop.blackduck.com')
  
  jwt = ''
  
   json_api_resource_headers = {
   'Content-Type': "application/vnd.api+json",
   'Accept': "application/vnd.api+json",
   'Authorization': 'Bearer ' + jwt
   }
  
  project_name = ''
  
  # step 1 get a project by name with included branches, extract a project ID and branch
  polaris.request("GET", f"/api/common/v0/projects?filter[project][name][$eq]={project_name}&include[project][]=branches&page[limit]=1&page[offset]=0", None, json_api_resource_headers)
  projects_response = polaris.getresponse()
  print(f'Projects with included branches: \n{json.dumps(projects_response.read(), indent=4)}')
  
  project_id = ''
  branch_id = ''
  
  # step 2 use the project and branch IDs to get the list of open issues
  polaris.request("GET", f"/api/query/v1/issues?project-id={project_id}&branch-id={branch_id}&page[limit]=100&page[offset]=0", None, json_api_resource_headers)
  issues_response = polaris.getresponse()
  print(f'Issues: \n{json.dumps(issues_response.read(), indent=4)}')
                      
                  

Java: Retrieve a List of Issues for a Project


  import okhttp3.OkHttpClient;
  import okhttp3.Request;
  import okhttp3.Response;
  
  final static String JSON_API_STRING = "application/vnd.api+json";
  
  String jwt = "";
  String host = "https://subdomain.cop.blackduck.com";
  
  OkHttpClient client = new OkHttpClient();
  
  String projectName = "";
  
  // step 1 get a project by name with included branches, extract a project ID and branch
  Request getProjectWithIncludedBranchesRequest = new Request.Builder()
    .url(host+"/api/common/v0/projects?filter[project][name][$eq]="+projectName+"&include[project][]=branches&page[limit]=1&page[offset]=0")
    .get()
    .addHeader("Accept", JSON_API_STRING)
    .addHeader("Authorization", "Bearer "+jwt)
    .build();
  
  Response getProjectWithIncludedBranchesResponse = client.newCall(getProjectWithIncludedBranchesRequest).execute();
  
  String projectId = "";
  String branchId = "";
  
 // step 2 use the project and branch IDs to get the list of open issues
 Request getProjectIssuesRequest = new Request.Builder()
     .url(host+"/api/query/v1/issues?project-id="+projectId+"&branch-id="+branchId+"&page[limit]=100&page[offset]=0")
     .get()
     .addHeader("Accept", JSON_API_STRING)
     .addHeader("Authorization", "Bearer "+jwt)
     .build();
  
  Response getProjectIssuesResponse = client.newCall(getProjectIssuesRequest).execute();