locked
TFS REST API: Where can I get the IDs for Users/Groups to use in REST API calls? RRS feed

  • Question

  • Various TFS REST API methods require you to specify the ID of a user or group that you're interested in (e.g. finding the profile info for the user, adding code reviewers, etc.). However, I can't see any way of obtaining the ID from the user/group name using the REST API. I can't even see a way of viewing the ID using the web interface.

    Surely if these IDs are required for the REST API they should be obtainable somehow from the REST API? Is there an easy way to get these or do I have to knock something up in .Net to extract the IDs?

    Thanks,

    John.

    Friday, January 20, 2017 11:29 AM

Answers

  • Hi Johnh,

    The UserId and group ID is stored in Tfs_Configuration database.

    If you want to know your ID, you could ask your TFS administrator to check the "[dbo].[tbl_Identity]" table to get your UserID. For the group ID, you could check the [dbo].[tbl_Group] table in your Tfs_Configuration database.

    Best regards


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, January 25, 2017 9:12 AM
    Moderator

All replies

  • Hi John,

    Thank you for posting here.

    You could use this REST API for accounts to get user IDs. You could get the IDs for all users and find which belongs to you.

    GET http://serverName:8080/tfs/_apis/Accounts?api-version=1.0

    Best regards


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Saturday, January 21, 2017 4:30 AM
    Moderator
  • I just get a 'Page not found' error when I try that. The documentation you linked to suggests that you have to supply a memberId or ownerId GUID to perform Get Accounts. It doesn't mention how you would go about finding the memberId or ownerId.


    I'm using TFS2017 (on-prem) if that makes a difference.
    • Edited by JohnH_Work Monday, January 23, 2017 4:37 PM added note
    Monday, January 23, 2017 4:30 PM
  • After some playing around I've managed to find an undocumented Groups API method (if it's not undocumented then it's very well hidden) that works at the server level and at the collection level.

    E.g.

    http://serverName:8080/tfs/_apis/Groups?api-version=1.0
    or
    http://serverName:8080/tfs/DefaultCollection/_apis/Groups?api-version=1.0
    Only problem is that the 'members' and 'memberIds' properties that it returns are null for all of my groups.

    Actually, there's another problem which is that I really need the Groups at the Team Project level, and that doesn't seem to work.
    • Edited by JohnH_Work Monday, January 23, 2017 5:25 PM more woe
    Monday, January 23, 2017 5:10 PM
  • Hi JohnH,

    Sorry for the mistake that the Account REST API is only supports for VSTS not TFS 2017. Because it needs must use OAuth Authenticate method and TFS 2017 doesn't add this type of Authenticate method currently.

    And I'm afraid that there's no such "http://serverName:8080/tfs/_apis/Groups?api-version=1.0" API published officially.

    So which REST API you use to let you enter a memberID, could you please share it to me?


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Tuesday, January 24, 2017 3:50 AM
    Moderator
  • I'm using _api/policy/configurations to create branch Required Reviewers branch policies (https://www.visualstudio.com/en-us/docs/integrate/api/policy/settings#required-reviewers-policy). It requires the group or member Ids for the requiredReviewerIds property of the settings.

     I've got it working, but I have to manually create a branch policy with the required user or group, fetch the details using the api to get the reviewer Id, then delete it so I can create the branch policy I actually want with the api.

    Ideally I just want to be able to write a script where I just pass in the name of the user or group who will be reviewing and it then finds the Id automatically (or they could add the ability to have partial branch name matching to the web interface for branch policies).

    Tuesday, January 24, 2017 9:56 AM
  • Hi Johnh,

    The UserId and group ID is stored in Tfs_Configuration database.

    If you want to know your ID, you could ask your TFS administrator to check the "[dbo].[tbl_Identity]" table to get your UserID. For the group ID, you could check the [dbo].[tbl_Group] table in your Tfs_Configuration database.

    Best regards


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, January 25, 2017 9:12 AM
    Moderator