Query all Azure DevOps pull requests one user created based on AAD user ID

Viewed 106

Building an ASP.NET Core Web API. Need to query all pull requests the user created.

I have got the current user's AAD user Id already. Like: 869fcc0e-55c0-4df3-9cd6-8a2da2d2305f

Writing it this way:

var credentials = new VssBasicCredential(userName: string.Empty, password: this.config.Key);
var vssConnection = new VssConnection(new Uri(this.config.BaseUrl), credentials);
var gitClient = vssConnection.GetClient<GitHttpClient>();

var searchCriteria = new GitPullRequestSearchCriteria
{
    TargetRefName = this.config.BranchName,
    Status = PullRequestStatus.All,
    CreatorId = Guid.Parse(userId); <---- Problem here!
};

IEnumerable<GitPullRequest> allPrs = await gitClient.GetPullRequestsAsync(
    project: this.config.ProjectName,
    repositoryId: this.config.RepositoryId,
    searchCriteria: searchCriteria,
    skip: skip,
    top: take);

return allPrs.OrderByDescending(t => t.CreationDate);

But I can't get a result. I found that it might be possible that Azure DevOps user id might not be the same concept of the user's AAD id.

So what is the correct way to query all the pull requests one user created based on his AAD user ID?

(Prefer to use the C# SDK instead of rest API)

0 Answers
Related