What are the available fields in the Web API?

Must-share information (formatted with Markdown):

  • Version 8.9.10
  • Through Zip file
  • what are you trying to achieve: Trying to get the different report metrics using the web API
  • I have my code as the following:
metricsKeys = ['code_smells', 'critical_violations', 'minor_violations', 'major_violations',
                    'blocker_violations', 'security_hotspots_reviewed', 'complexity', 'duplicated_blocks', 'last_commit_date', 'reliability_remediation',
                    'functions', 'comment_lines_density', 'comment_lines', 'ncloc_language_distribution', 'lines', 'security_remediation_effort',
                    'quality_profiles', 'duplicated_lines', 'sqale_index', 'ncloc', 'sqale_rating', 'coverage', 'security_review_rating', 'confirmed_issues',
                    'reliability_rating', 'files', 'line_coverage', 'alert_status', 'security_rating', 'quality_gate_details', 'development_cost',
                     'bugs', 'sqale_debt_ratio', 'open_issues', 'duplicated_lines_density', 'statements', 'cognitive_complexity', 'vulnerabilities', 'security_hotspots', 'security_hotspots_reviewed' ]

sample = sq_user.measures.get_component_with_specified_measures(component= project_name,
                                                             fields="metrics, periods",
                                                             metricKeys=metricsKeys)

But the returned object is:

{'component': {'key': project_key,
  'name': project_name,
  'qualifier': 'TRK',
  'measures': [{'metric': 'code_smells', 'value': '7', 'bestValue': False}]}}

Why am I not getting the rest of the metrics?

Do I have to use some other fields?

I tried searching the web API documentation but could not find a list of the fields which can be used for the web API.

Any help?

Hi,

/api/metrics/search?ps=500 should give the available metrics
and i.e.
api/measures/component?component=$sonar.projectKey&additionalFields=metrics&metricKeys=ncloc,complexity,violations
should return the metrics for nloc,complexity and violations for the given component.

Gilbert

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.