通过访问令牌,使用Azure DevOps中的REST API获取用户详细信息

时间:2019-12-12 11:35:02

标签: azure-devops

在我们的APP中,我们具有Azure DevOps上用户的用户令牌。我们使用它来使用REST API在Azure DevOps实例中执行某些操作。为了忽略由该特定用户执行的操作触发的Webhook,我们需要知道该用户的电子邮件。是否可以提供API?

根据文档https://docs.microsoft.com/en-us/rest/api/azure/devops/profile/profiles/get?view=azure-devops-rest-5.1的建议,我尝试用monster = file.read().split(',') # assuming "," is the delimiter 代替GET https://app.vssps.visualstudio.com/_apis/profile/profiles/{id}?api-version=5.1的{​​{1}},但它抛出“ 找不到资源”错误。

1 个答案:

答案 0 :(得分:0)

  

我们需要知道用户的电子邮件。是否有可以提供的API   那?

对于此问题,您可以使用Users - List rest api来实现。

样品请求:

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

样品响应:

{
      "subjectKind": "user",
      "metaType": "member",
      "domain": "LOCAL AUTHORITY",
      "principalName": "TeamFoundationService (TEAM FOUNDATION)",
      "mailAddress": "xxx.@xxx.com",
      "origin": "vsts",
      "originId": "00ca946b-2fe9-4f2a-ae2f-40d5c48001bc",
      "displayName": "TeamFoundationService (TEAM FOUNDATION)",
      "_links": {
        "self": {
          "href": "https://vssps.dev.azure.com/Fabrikam/_apis/Graph/Users/acs.Nzc4OWYwOWQtZTA1My00ZjJlLWJkZWUtMGM4Zjg0NzZhNGJj"
        },
        "memberships": {
          "href": "https://vssps.dev.azure.com/Fabrikam/_apis/Graph/Memberships/acs.Nzc4OWYwOWQtZTA1My00ZjJlLWJkZWUtMGM4Zjg0NzZhNGJj"
        },
        "membershipState": {
          "href": "https://vssps.dev.azure.com/Fabrikam/_apis/Graph/MembershipStates/acs.Nzc4OWYwOWQtZTA1My00ZjJlLWJkZWUtMGM4Zjg0NzZhNGJj"
        },
        "storageKey": {
          "href": "https://vssps.dev.azure.com/Fabrikam/_apis/Graph/StorageKeys/acs.Nzc4OWYwOWQtZTA1My00ZjJlLWJkZWUtMGM4Zjg0NzZhNGJj"
        },
        "avatar": {
          "href": "https://dev.azure.com/Fabrikam/_apis/GraphProfile/MemberAvatars/acs.Nzc4OWYwOWQtZTA1My00ZjJlLWJkZWUtMGM4Zjg0NzZhNGJj"
        }
      },
      "url": "https://vssps.dev.azure.com/Fabrikam/_apis/Graph/Users/acs.Nzc4OWYwOWQtZTA1My00ZjJlLWJkZWUtMGM4Zjg0NzZhNGJj",
      "descriptor": "acs.Nzc4OWYwOWQtZTA1My00ZjJlLWJkZWUtMGM4Zjg0NzZhNGJj"
    }

您可以从响应正文中的 mailAddress 变量获取用户的电子邮件。通过在Users-Get rest api中指定 descriptor 参数,您可以获取特定用户的详细信息。