Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Rules param is not deprecated as using it return rule measures
DescriptionGet a list of resourcescomponents

URL

/api/resources

HTTP MethodGET
Response Formatsjson | xml

Security

Requires User role Browse permission on resource

Examples

Use CaseExample Request
Get all the projects

GET http://nemo.sonarsource.org/api/resources

For each project, get lines of code and code coverage measures
Get lines of code and code coverage measures for project org.codehaus.sonar:sonar
GET http://nemo.sonarsource.org/api/resources?resource=org.codehaus.sonar:sonar&metrics=ncloc,coverage
Get all the resources included in project org.codehaus.sonar:sonar: packages, files, etc.
GET http://nemo.sonarsource.org/api/resources?resource=org.codehaus.sonar:sonar&depth=-1
Get all the files included in project org.codehaus.sonar:sonar

GET http://nemo.sonarsource.org/api/resources?resource=org.codehaus.sonar:sonar&depth=-1&scopes=FIL

Hotspot of the ten files with the worst code coverage for project org.codehaus.sonar:sonar

GET http://nemo.sonarsource.org/api/resources?resource=org.codehaus.sonar:sonar&depth=-1&scopes=FIL&metrics=coverage&limit=10

Get lines of code measure of direct children of org.codehaus.sonar:sonar

GET http://nemo.sonarsource.org/api/resources?resource=org.codehaus.sonar:sonar&depth=1&metrics=ncloc

Get code coverage on new code for project org.codehaus.sonar:sonar for all differential periods.
GET http://nemo.sonarsource.org/api/resources?resource=org.codehaus.sonar:sonar&metrics=new_coverage&includetrends=true

...

Code Block
titleJSON
languagejavascript
[
  {
    "id":2865,
    "key":"org.codehaus.sonar:sonar",
    "name":"Sonar",
    "scope":"PRJ",
    "qualifier":"TRK",
    "date":"2012-08-10T04:03:51+0200",
    "creationDate":"2012-08-10T04:03:51+0200"
    "lname":"Sonar",
    "lang":"java",
    "version":"3.3-SNAPSHOT",
    "description":"Open source platform for continuous inspection of code quality",
 
    "p1":"previous_analysis",
    "p1p":"2012-08-09",
    "p1d":"2012-08-09T04:04:01+0200",
    "p2":"days","p2p":"7",
    "p2d":"2012-08-03T04:03:51+0200",
    ...
 
    "msr":[
      {
        "key":"coverage",
        "val":70.3,
        "frmt_val":"70.3%",
        "alert":null,
        "alert_text":null,
        "trend":0,
        "var":0,
        "var1":0.0,
        "var2":0.0,
        ...
      },
      ...
    ]
  }
]

...

Parameter

Description

RequiredDefault ValueExample Values

resource

id or key of the resource

NoNoneorg.codehaus.sonar:sonar

metrics

Comma-separated list of metric keys/ids.
Load measures on selected metrics. If only one metric is set, then measures are ordered by value.

NoNonelines,blocker_violations

depth

Used only when resource is set. 

  • 0: only selected resource 
  • -1: all children, including selected resource 
  • >0: depth toward the selected resource
No0-1

scopes

Comma-separated list of scopes:

  • PRJ: project/module 
  • DIR: directory (like Java package) 
  • FIL: file
NoNonePRJ,DIR

qualifiers

Comma-separated list of qualifiers

  • VW: view
  • SVW: sub-view
  • TRK: project 
  • BRC: module 
  • CLA: class 
  • UTS: unit test 
  • DIR: directory 
  • FIL: file
  • DEV: developer
NoNoneTRK,BRC
languages

Comma-separated list of language keys.
Since Sonar version 3.4.  Removed in 4.2.

NoNonejava,js

verbose

Add some data to response.
Possible values: true | false 

Nofalsetrue

limit

Limit the number of results. Only used if one metric, and only one, is set.

NoNone10

includetrends

Include trends and period variations in response: add <trend> (1 if better, else worse), <var> (1 if measure value increases) and nodes <p*> for period variations.
Possible values: true | false 

Nofalsetrue

includealerts

Include alerts data: add nodes <alert> (ERROR, WARN, OK) and <alert_text>
Possible values: true | false  

Nofalsetrue

rules

Filter on rules: setting it to true will return rules id and rule name for measure having such info (such as 'blocker_violations', 'critical_violations', ..., 'new_blocker_violations', ...)

Possible values: true | false | list of rule ids 

Nofalsetrue

rule_priorities

Deprecated. Use Issues web service instead.

Filter on rule priority: setting it to true or to a list of priorities (BLOCKER, CRITICAL, MAJOR, MINOR, INFO) will return measures having such info (such as 'blocker_violations', 'critical_violations', ..., 'new_blocker_violations', ...).
Possible values: true | false | list of priorities

NofalseBLOCKER,CRITICAL
format

Response

formats.
Possible values: json | xml

format can be set through:

  • Parameter format: xml | json
  • Or the 'Accept' property in the HTTP header:
    • Accept:text/xml
    • Accept:application/json
If nothing is set, json is used.
NoNonejson