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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With