如何使用 API 或 CLI 获取 Azure Devops 项目中的用户列表

How to get a list of users in an Azure Devops project using an API or CLI

我想知道是否有任何 cli 命令或 rest api 可以获取 Azure DevOps 项目中的用户列表。例如,在一个组织中,如果有两个项目“alpha”和“beta”,每个项目有 10 个用户。我能够通过 cli 或 rest api's 获取所有 20 个用户的列表。但是,如何才能只获取“alpha”项目中的用户列表?

你看过Azure Devops REST API

你只需要用项目名称设置范围。

GET https://vssps.dev.azure.com/{organization}/_apis/graph/users?subjectTypes={subjectTypes}&continuationToken={continuationToken}&scopeDescriptor={scopeDescriptor}&api-version=6.0-preview.1

同意 Sajeetharan 的观点

我们可以使用 API 和变量 scopeDescriptor 来获取一个项目中的用户列表。

步骤:

List all projects 并获取“alpha”项目 ID。

GET https://dev.azure.com/{organization}/_apis/projects?api-version=6.0

通过Descriptors - Get

获取一个项目scopeDescriptor
GET https://vssps.dev.azure.com/{organization}/_apis/graph/descriptors/{storageKey}?api-version=5.0-preview.1

注意:我们需要在字段storageKey中输入“alpha”项目ID,然后将value的值复制到scopeDescriptor 下面共享的 API 字段。

GET https://vssps.dev.azure.com/{organization}/_apis/graph/users?scopeDescriptor={scopeDescriptor}&api-version=6.0-preview.1

那我们只能得到“alpha”项目的用户列表。