How to get Total lines added and lines removed in Pull requests ADO REST API response

Anonymous
2025-10-23T16:44:19.3+00:00

Hi, I’m trying to retrieve the total number of lines added and removed in a Pull Request (PR) using the Azure DevOps REST API.

I’ve tried using the following endpoints:

GET /_apis/git/repositories/{repositoryId}/pullRequests/{pullRequestId}/iterations/{iterationId}/changes

GET /_apis/git/repositories/{repositoryId}/pullRequests/{pullRequestId}/commits

GET /_apis/git/repositories/{repositoryId}/diffs

However, in most cases, the API responses either show 0 for changeCounts or don’t include line-level stats at all. Even though the PR UI in Azure DevOps correctly displays the number of lines added and removed, the REST API seems not to include those counts directly.

I’m looking for a reliable REST API (or combination of endpoints) to:

Get total lines added and removed across all changed files in a PR.

Optionally get per-file line additions/removals.

Here’s an example of what I’ve tried so far:

GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/pullRequests/{pullRequestId}/iterations/{iterationId}/changes?api-version=7.1-preview.1

and

GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/diffs?baseVersionType=PullRequest&baseVersion={pullRequestId}&targetVersionType=Commit&targetVersion=HEAD&api-version=7.1-preview.1

Both return metadata about changed files, but the line additions/deletions are always 0.Hi,

I’m trying to retrieve the total number of lines added and removed in a Pull Request (PR) using the Azure DevOps REST API.

I’ve tried using the following endpoints:

GET /_apis/git/repositories/{repositoryId}/pullRequests/{pullRequestId}/iterations/{iterationId}/changes

GET /_apis/git/repositories/{repositoryId}/pullRequests/{pullRequestId}/commits

GET /_apis/git/repositories/{repositoryId}/diffs

However, in most cases, the API responses either show 0 for changeCounts or don’t include line-level stats at all.
Even though the PR UI in Azure DevOps correctly displays the number of lines added and removed, the REST API seems not to include those counts directly.

I’m looking for a reliable REST API (or combination of endpoints) to:

Get total lines added and removed across all changed files in a PR.

Optionally get per-file line additions/removals.

Here’s an example of what I’ve tried so far:

GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/pullRequests/{pullRequestId}/iterations/{iterationId}/changes?api-version=7.1-preview.1

and

GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/diffs?baseVersionType=PullRequest&baseVersion={pullRequestId}&targetVersionType=Commit&targetVersion=HEAD&api-version=7.1-preview.1

Both return metadata about changed files, but the line additions/deletions are always 0.

Azure DevOps

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.