How to get the userId field in Azure Devops API
Asked Answered
W

3

7

I have to use this API : PATCH https://vsaex.dev.azure.com/{organisation}/_apis/userentitlements/{userId} to give read access to some projects to all users in my organisation. I am able to call this API, with success, but I don't know how to get the right GUID for the users. (To get the right Guid for the user I used Fiddler to spy the request).

When I use this API, (GET https://vssps.dev.azure.com/{organisation}/_apis/graph/users?api-version=6.0-preview.1) I get all users of my organisation, but in the list, there no the userId, I have only the originId, and it is the guid from the AAD, and I cannot update the user with that information.

I tried too to use the descriptor field, without any success. Does somebody have an idea to get this specific userId?

Example of User list I get with this API :

{
    "count": 133,
    "value": [{
        "subjectKind": "user",
        "metaType": "member",
        "directoryAlias": "COD0001",
        "domain": "10a83eaa-05c5-4b22-a201-63cddba4fe8c",
        "principalName": "[email protected]",
        "mailAddress": "[email protected]",
        "origin": "aad",
        "originId": "7c3408d6-62f4-43ff-bdbe-5be97000ba30",
        "displayName": "Personne bidon",
        "_links": {
            "self": {
                "href": "https://vssps.dev.azure.com/BIDON/_apis/Graph/Users/aad.ZDYzNzUwNzctNWJjYy03ZTkzLWIzZGUtMDEzNTdhM2JiMDIx"
            },
            "memberships": {
                "href": "https://vssps.dev.azure.com/BIDON/_apis/Graph/Memberships/aad.ZDYzNzUwNzctNWJjYy03ZTkzLWIzZGUtMDEzNTdhM2JiMDIx"
            },
            "membershipState": {
                "href": "https://vssps.dev.azure.com/BIDON/_apis/Graph/MembershipStates/aad.ZDYzNzUwNzctNWJjYy03ZTkzLWIzZGUtMDEzNTdhM2JiMDIx"
            },
            "storageKey": {
                "href": "https://vssps.dev.azure.com/BIDON/_apis/Graph/StorageKeys/aad.ZDYzNzUwNzctNWJjYy03ZTkzLWIzZGUtMDEzNTdhM2JiMDIx"
            },
            "avatar": {
                "href": "https://dev.azure.com/BIDON/_apis/GraphProfile/MemberAvatars/aad.ZDYzNzUwNzctNWJjYy03ZTkzLWIzZGUtMDEzNTdhM2JiMDIx"
            }
        },
        "url": "https://vssps.dev.azure.com/BIDON/_apis/Graph/Users/aad.ZDYzNzUwNzctNWJjYy03ZTkzLWIzZGUtMDEzNTdhM2JiMDIx",
        "descriptor": "aad.ZDYzNzUwNzctNWJjYy03ZTkzLWIzZGUtMDEzNTdhM2JiMDIx"
    },
    ...
    ]

}

Wandis answered 3/9, 2020 at 20:17 Comment(0)
W
7

To get id you should use User Entitlements - Search User Entitlements which is

GET https://vsaex.dev.azure.com/{organization}/_apis/userentitlements?api-version=6.0-preview.3

then you will get response like

"members": [
        {
            "id": "<YOUR ID HERE>",
            "user": {
                "subjectKind": "user",
                "metaType": "member",
                "domain": "Windows Live ID",
Waddell answered 3/9, 2020 at 21:13 Comment(0)
N
1

Another option is use az cli.

1 - First you need to install the az cli extension if it is not installed.

az extension list-available --output table | grep devops
az extension add --name azure-devops

2 - Configure organization if is needed

az devops configure --defaults organization=https://dev.azure.com/myorganization

3 - maybe you need to do a login and insert de devops PAT token (paste it)

az devops login
token:

4 - Use de command user list with the option --top if you need to show more than 200 users

az devops user list --top 15000 

5 - Use pipe with grep command to filter or send it to a file to find the user that you want to find.

az devops user list --top 15000 > devops-users.txt
az devops user list --top 5000 | grep [email protected]

6 - the field that you want is the id:

  "id": "a69fdd3c-yyyyy-6fa6-90ba-xxxxxx",

If you has permissions you can use also de command az devops user show

az devops user show --user [email protected]

Docs:

install az cli extension

az devops user

Noma answered 26/5, 2022 at 12:6 Comment(0)
T
0

Use this API to get all of the user's information in the organization.

GET https://vsaex.dev.azure.com/{organization}/_apis/userentitlements?api-version=5.1-preview.2

If you want to get a particular user by the Id, use this API:

GET https://vsaex.dev.azure.com/{organization}/_apis/userentitlements/{userId}?api-version=5.1-preview.2

By using these APIs, you will able to fetch the user details from the object id.

Thursday answered 4/5, 2023 at 15:12 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.