REST API

NOTE: The REST API is currently in alpha version. This means we are likely to make breaking changes in the next release. We also plan to expand the API to make more analysis information available. Contact Empear, and we are happy to share our detailed plans and get your feedback.

You can get the following information from the API:

  • The access user

  • The rest api documentation url

  • Project lists

  • Single project details

  • Analyses List of a project

  • Single analysis details

  • Hotspot list from an analysis, optionally you can you filter the output by numberofdefects, size, number of revisions

  • Architecture hotspot lists and system health for an analysis

The REST API user

CodeScene lets you create a user intended to consume the REST API. Login as administrator and create a RestApi user as illustrated in Fig. 33.
If you are using LDAP, you need to assign the RestApi role. Follow the instructions from LDAP Roles Settings to assign a role to a LDAP user.
OAuth user accounts are not supported.
Configure a RestApi user

Fig. 33 Configure a RestApi user to consume the REST API.

To consume the REST API, you need to authenticate using http basic authentication.
The REST API follows the default project access, project access mode and collaborators described in Project Access Management

The REST API documentation URL

You can browse the REST API functions here CodeScene RestAPI Functions. Before trying any functionality, use the Authorize button then fill in your username and password to authenticate.
The version in use is v1

Project lists

curl -X GET --header 'Accept: application/json' -u username:password \
'http://localhost:3003/api/v1/projects'

Single project details

curl -X GET --header 'Accept: application/json' -u username:password \
'http://localhost:3003/api/v1/projects/{project-id}'
  • Replace {project-id} with a valid id taken from the project list results.

Analysis List of a project

curl -X GET --header 'Accept: application/json' -u username:password \
'http://localhost:3003/api/v1/projects/{project-id}/analyses'
  • Replace {project-id} with a valid id taken from the project list results.

Single analysis details

Single analysis details using its id
curl -X GET --header 'Accept: application/json' -u username:password \
'http://localhost:3003/api/v1/projects/{project-id}/analyses/{analysis-id}'
  • Replace {project-id} with a valid id taken from the project list results.

  • Replace {analysis-id} with a valid id taken from the analysis list results.

Latest analysis details
curl -X GET --header 'Accept: application/json' -u username:password \
'http://localhost:3003/api/v1/projects/{project-id}/analyses/latest'
  • Replace {project-id} with a valid id taken from the project list results.

Hotspot list from an analysis

You can filter the result by number_of_defects, lines_of_code and change_frequency, in any combination of them.
Hotspot list using analysis id
curl -X GET --header 'Accept: application/json' -u username:password \
'http://localhost:3003/api/v1/projects/{project-id}/analyses/{analysis-id}/hotspots'
  • Replace {project-id} with a valid id taken from the project list results.

  • Replace {analysis-id} with a valid id taken from the analysis list results.

Hotspot list using analysis id - only hotspots with change_frequency >= 70 and lines_of_code => 100
curl -X GET --header 'Accept: application/json' -u username:password \
'http://localhost:3003/api/v1/projects/{project-id}/analyses/latest/hotspots?change_frequency=70&lines_of_code=100'
  • Replace {project-id} with a valid id taken from the project list results.

  • Replace {analysis-id} with a valid id taken from the analyses list results.

Top 15% Hotspot list using analysis id based on number of defects
curl -X GET --header 'Accept: application/json' -u username:password \
'http://localhost:3003/api/v1/projects/{project-id}/analyses/{analysis-id}/hotspots/numberofdefectspercentage/top/15'
  • Replace {project-id} with a valid id taken from the project list results.

  • Replace {analysis-id} with a valid id taken from the analyses list results.

  • Replace 15 with whatever percentage you like.

Top 25% Hotspot list using analysis id based on change frequency
curl -X GET --header 'Accept: application/json' -u username:password \
'http://localhost:3003/api/v1/projects/{project-id}/analyses/{analysis-id}/hotspots/changefrequencypercentage/top/25'
  • Replace {project-id} with a valid id taken from the project list results.

  • Replace {analysis-id} with a valid id taken from the analysis list results.

  • Replace 25 with whatever percentage you like.

Latest analysis hotspot list
curl -X GET --header 'Accept: application/json' -u username:password \
'http://localhost:3003/api/v1/projects/{project-id}/analyses/latest/hotspots'
  • Replace {project-id} with a valid id taken from the project list results.

Latest analysis hotspot list - only hotspots with number_of_defects >= 10 and lines_of_code => 100
curl -X GET --header 'Accept: application/json' -u username:password \
'http://localhost:3003/api/v1/projects/{project-id}/analyses/latest/hotspots?number_of_defects=10&lines_of_code=100'
  • Replace {project-id} with a valid id taken from the project list results.

Latest analysis, top 5% hotspot list based on number of defects
curl -X GET --header 'Accept: application/json' -u username:password \
'http://localhost:3003/api/v1/projects/{project-id}/analyses/latest/hotspots/numberofdefectspercentage/top/5'
  • Replace {project-id} with a valid id taken from the project list results.

  • Replace 5 with whatever percentage you like.

Latest analysis, top 10% hotspot list based on change frequency
curl -X GET --header 'Accept: application/json' -u username:password \
'http://localhost:3003/api/v1/projects/{project-id}/analyses/latest/hotspots/changefrequencypercentage/top/10'
  • Replace {project-id} with a valid id taken from the project list results.

  • Replace 10 with whatever percentage you like.

Architecture hotspot lists and system health for an analysis

Architecture hotspot list using analysis id
curl -X GET --header 'Accept: application/json' -u username:password \
'http://localhost:3003/api/v1/projects/{project-id}/analyses/{analysis-id}/architecture/hotspots'
  • Replace {project-id} with a valid id taken from the project list results.

  • Replace {analysis-id} with a valid id taken from the analysis list results.

Latest analysis architecture hotspot list
curl -X GET --header 'Accept: application/json' -u username:password \
'http://localhost:3003/api/v1/projects/{project-id}/analyses/latest/architecture/hotspots'
  • Replace {project-id} with a valid id taken from the project list results.