Lines of code count for License is off

I wrote a script that went through every branch of every project to get the max lines of code. When I add these up I get 892,063 but the License Manager says we are at 999,966. I compared the locs from my script to what I see in the projects screen in the UI and they match the lower number.

Get all projects snippet

    $ProjectsApiUrl = "$SonarUrl/api/projects/search?ps=500&p=$page"   

Get all branches call snippet

$BranchesApiUrl = "$SonarUrl/api/project_branches/list?project=$ProjectKey"

Snag lines of code for a branch snippet

$MeasuresApiUrl = "$SonarUrl/api/measures/component?component=$ProjectKey&branch=$BranchName&metricKeys=ncloc"
$BranchLOC = ($MeasuresResponse.component.measures | Where-Object { $_.metric -eq "ncloc" } | Select-Object -ExpandProperty value) -as [int]

Is this a bug or am I doing somehging wrong?

Thanks
Rob

What version of SonarQube are you using? This information is requested in the template post.

Non-Prod 2025.1.3
Production 10.6.1

Thanks!

For what it’s worth, the endpoints you’ve mentioned make sense to me, except that you also need to query for pull requests (SONAR-15450).

You might want to check out the GET api/projects/license_usage API. It can help you verify if those values add up as expected—whether it’s to the lower or higher total. This API also allows you to drill down into specific projects to identify any variations.