Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSTS Pull request API - how to get the IdentityRef

I am using VSTS Pullrequest create API method to automate the PR creation, in the request i need to provide various IdentityRef id values for createdby/autocompleteby/reviewers properties. In my case all i have is user details (like full name, email address - [email protected] ), in this case how do i retrieve the IdentityRef Guid so that i can pass it to PR Create API.

https://docs.microsoft.com/en-us/rest/api/azure/devops/git/pull%20requests/create?view=azure-devops-rest-5.0

Any help is appreciated.

like image 915
Mahender Avatar asked Dec 30 '18 00:12

Mahender


2 Answers

1) Use Graph - List Users, but also check for a X-MS-ContinuationToken response header to determine if there is still additional paged data to be retrieved. If so, resend the request with the continuation token value until all values are returned:

  • GET https://vssps.dev.azure.com/{organization}/_apis/graph/users?api-version=5.0-preview.1, followed by
  • GET https://vssps.dev.azure.com/{organization}/_apis/graph/users?continuationToken={continuationToken}&api-version=5.0-preview.1

(I'm wondering if this is why you are only getting 500 users per your comment above. Unfortunately the documentation doesn't list the max page size for this API. If you are using the continuation token and all users are not being returned, that sounds like an API bug to me.)

2) Use Get User Entitlements. This provides top and skip parameters. The top parameter has a 10000 record limit per the documentation.

  • GET https://vsaex.dev.azure.com/{organization}/_apis/userentitlements?top=10000&api-version=5.0-preview.2
like image 92
Eric Munn Avatar answered Dec 24 '22 06:12

Eric Munn


An easier approach is to use Identities - Read Identities API, which allows us to query for the IdentityRef of a user by email, by IdentityDescriptors, by ids, by name and by SubjectDescriptors. This avoids the costly approach of having to fetch the user graph repeatedly to locate a single user and also helps in directly getting the IdentityRef and not just the user descriptor.

like image 32
Arunothia Marappan Avatar answered Dec 24 '22 07:12

Arunothia Marappan