TFS - Given a personal access token, how can I get my username? - tfs

I would like to be able to get the User ID that owns a TFS Personal Access Token.
I cannot seem to find any TFS rest web services that do this.
I thought maybe I could use the "get my branches" web service and take the owner of the branch, but unfortunately this does not work because "my branches" are often created by other people.
Is this possible?

I am afraid there isnot a way to get the User Id of the user who creates the PAT by given the PAT.
But if you just want to get your userId you can refer to below rest api.
You can check out get team members rest api. If you are a team member in the team. You can get your userId in the response result.
GET https://{instance}/{collection}/_apis/projects/{projectId}/teams/{teamId}/members?api-version=5.0
See below example in powershell scripts:
$url="https://{instance}/{collection}/_apis/projects/{projectId}/teams/{teamId}/members?api-version=5.0"
$pat='{PAT}'
$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($pat)"))
$result1 = Invoke-RestMethod -Uri $url -Headers #{authorization = "Basic $base64AuthInfo"} -Method Get
You can get the TeamId of your team on the webpage address bar (Project settings-->Teams-->Select the team you are a member of)
You can also create a work item and then call get work item rest api to get the workitem details. You will see your userId in the System.CreatedBy field of the response result.
GET https://{instance}/{collection}/{project}/_apis/wit/workitems/{id}?api-version=5.0

Related

Updating isOnlineMeeting in M365 event via MS Graph

What I'm doing is creating a calendar event in M365 via the EWS API. I want to set isOnlineMeeting and onlineMeetingProvider, but those properties are not writable in EWS. So my idea was to take the itemId of the new event, and use Microsoft Graph to update just those two properties. I had to alter the itemId a bit to get Graph to accept it (changed / to -) but it appears to "work" in the sense that the PATCH command comes back with response 200. But the properties do not get modified. Here is the json that I give to the PATCH command:
{
"isOnlineMeeting": true,
"onlineMeetingProvider": "teamsForBusiness"
}
Here is the URL (shortened for brevity):
PATCH /v1.0/users/me/calendars/AQMkAG.../events/AAMkAG...
As I said, the http response code is 200. The output from the PATCH is a listing of all of the event properties. The ones I am trying to modify are unchanged. The funny thing is, I could have sworn I had this working last week, but my tests this week all fail. Any ideas?

Microsoft Graph API GET onlineMeeting via joinUrl

Current using Microsoft Graph API v1.0 to create onlineMeetings via POST /me/events. Reason being, if you create an onlineMeeting directly and add a user in the meeting, it doesn't create a calendar event.
The params I use for that call is:
:isOnlineMeeting => true,
:onlineMeetingProvider => "teamsForBusiness"
Which works great and returns a joinUrl under onlineMeetings.
However, I'd like to pull attendance data from the GET onlineMeeting route to get attendance information since the attendees section of the event only seems to return users that were added to the actual event, not who attended the actual onlineMeeting.
I have tried doing a get request like such:
/v1.0/me/onlineMeetings?$filter=joinWebUrl%20eq%20'https://whateverthejoinurlis'
but the response says it's not a valid filter.
Any guidance would be appreciated.
Posting the Answer for better knowledge
Copying from #Shiva Keshav Varma comments
Try it in beta version
/beta/me/onlineMeetings?$filter=joinWebUrl%20eq%20'https://whateverthejoinurlis
You can also get the attendeereport using beta/users/{userId}/onlineMeetings/{meetingId}/attendeeReport as specified in the document.

Can not get bulk manager data from Microsoft graph

I want to get all user's and their corresponding manager data from the organization.
In Microsoft Graph explorer I do this:
request: GET V1.0
url: https://graph.microsoft.com/v1.0/users?$select=displayName,manager
privileges: I select all existing privileges from the list.
Data for the manager is not coming. But I can see the data for "displayName".
For each user when I separately do a request like this:
https://graph.microsoft.com/v1.0/users/{...user id...}/manager
then I can get the manager data, but I can not get it bulk from the /users?$select endpoint. The organization has 1200 users And I don't want to make 1200 requests to Graph API to get the manager data for each user, instead I want to get the manager data in one request (bulk).
Can please someone help me with this?
Try this :
https://graph.microsoft.com/v1.0/users/<user obj id>?$expand=manager
Result:

some existing users cant be found in TFS2018 workitem 'assigned to' field. even they are added to team project

My customer are using TFS2018 update2 version. and AD is used to manager TFS user.
there are about 1000 users right now. and about 10 to 20 users reported that their user account can't be found in TFS workitem "Assigned to" field. so strange and confused!
1) we did check the 'AssignedTo' field of the workitem setting, is is of default setting, which allows existing user and valid users.
2) the users are even added to the team project, however, they can't be found when using search in 'assigned to 'field.
3) tried other type of workitems, any projects. same issues.
Generally speaking, such users can be added to team project successfully.and they can't be found in 'assigned to' filed of all workitems in all projects. so we doubt it is some kind of user account sync issues?
and we did do more investigation and debugging. and we found a para named operationScopes,and its value is 'ims';and if we add value 'ad' to this array. the users can be found! and we noticed the returned value bdifference between such 'bad users' and 'good users' are of the 'Local directory'and 'localId' field. the value is null here, for good user, neither local directory nor LocalID is null.
hope this clue works.
http://TFS2018server:8080/tfs/TFSCollection/_apis/IdentityPicker/Identities
and add more clues, we updated the Web Services_static\tfs\Dev16.M122.5_script\TFS\debug\VSS\Identities\Picker\Services.js; by adding queryScopes.push("ims") in the OperationScope.IMS switch, then the users can be found. and I know, it is not a good way to update TFS code, it is just to do debugging. hope it is useful.
Based on the investigation and testing, seems it's the AD sync issue. That means the missed users may not be synced to TFS.
So when you query the missed user in AD you can find it (Add value 'ad' to operationScopes), but in TFS you can not find them.
TFS use a background synchronization job, scheduled every hour, to look for changes in Active Directory (or the local machine workgroup if the server is not domain joined). You can force the job to run using any of these techniques: How to synchronize TFS users with AD
It could be that you still do not see the user or name listed in the UI even if synchronization is working. The synchronization job does not automatically creates a user profile in the database for every user or group in the database, to avoid useless growth in big enterprises.
In such a case, the first time you use a new AD account (user or group), you must refer to it using DOMAIN\account syntax so that TFS look up in AD on the fly and insert a profile record in the database for the account.
Further Troubleshooting
Mr. Hinsh has a good troubleshooting guide if you still have troubles. It's still apply to TFS 2018 Update2
I have the same issue in Azure DevOps Server 2019 (Version Dev17.M153.3)
when I tried to add a user to a security group it shows the user but it cannot retrieve the scopeName such that if there is any other user in other domains with the same username it raises the following error
Multiple identities found matching 'theusername'. Use the unique name
to specify one of the following identities:
fullname1 (unique name: domain1\theusername)
fullname2 (unique name: domain2\theusername)
but the same user in other collection is working.
in C:\Program Files\Azure DevOps Server 2019\Application Tier\Web Services_static\tfs\Dev17.M153.3_scripts\TFS\debug\VSS\Identities\Picker\Services.js queryScopes.push("ims") was already there.
after some investigation i could reduce the problem to the following powershell code
$url1 = "https://tfsserver/CB/_apis/IdentityPicker/Identities?api-version=5.1-preview.1"
$Body = '{"query":"mydomainname\\myusername","identityTypes":["user","group"],"operationScopes":["ims","ad","wmd"],"properties":["DisplayName","IsMru","ScopeName","SamAccountName","Active","SubjectDescriptor","Department","JobTitle","Mail","MailNickname","PhysicalDeliveryOfficeName","SignInAddress","Surname","Guest","TelephoneNumber","Description"],"filterByAncestorEntityIds":[],"filterByEntityIds":[],"options":{"MinResults":40,"MaxResults":40,"ExtensionId":"F12CA7AD-00EE-424F-B6D7-9123A60F424F","ProjectScopeName":"ateamprojectname","CollectionScopeName":"badcollection","Constraints":[]}}'
$x= Invoke-Webrequest $url1 -Method POST -ContentType application/json -UseDefaultCredentials -Body $Body
$y = $x.Content | ConvertFrom-Json
Write-Host "badcollection->", $y.results.identities.scopeName
$url1 = "https://tfsserver/CB_TestCollection/_apis/IdentityPicker/Identities?api-version=5.1-preview.1"
$Body = '{"query":"mydomainname\\myusername","identityTypes":["user","group"],"operationScopes":["ims","ad","wmd"],"properties":["DisplayName","IsMru","ScopeName","SamAccountName","Active","SubjectDescriptor","Department","JobTitle","Mail","MailNickname","PhysicalDeliveryOfficeName","SignInAddress","Surname","Guest","TelephoneNumber","Description"],"filterByAncestorEntityIds":[],"filterByEntityIds":[],"options":{"MinResults":40,"MaxResults":40,"ExtensionId":"F12CA7AD-00EE-424F-B6D7-9123A60F424F","ProjectScopeName":"ateamprojectname","CollectionScopeName":"goodCollection","Constraints":[]}}'
$x= Invoke-Webrequest $url1 -Method POST -ContentType application/json -UseDefaultCredentials -Body $Body
$y = $x.Content | ConvertFrom-Json
Write-Host "goodcollection->", $y.results.identities.scopeName
the output result for the first write-host is "badcollection->"
but the output result for the second write-host is "goodcollection->mydomainname"
the questions are:
Why does it depend on collection?
How can i force tfs to sychronize that user account for the badcollection as well as the good collection.

How can I get the siteId of the current site with Microsoft Graph API?

From the documentation, I can't find any ways to get the siteId of the site where I put the webpart in.
For example,
My current site is: https://{hostname}/sites/main1 <-- NOT root site, but I want to get this siteId
and I test my webpart here: https://{hostname}/sites/main1/_layouts/15/workbench.aspx
How can I achieve this? From the documentation,
A site is addressed be a unique identifier which is a composite ID of the following values:
Site collection hostname (contoso.sharepoint.com)
Site collection unique ID (guid)
Site unique ID (guid)
I can get the hostname easily by using location.hostname (Yes, I am using JavaScript + React to build my webpart) but how to get the site-id easily with Graph API?
Try this: https://graph.microsoft.com/v1.0/sites/{hostname}:/sites/{path}?$select=id
For example:
https://graph.microsoft.com/v1.0/sites/cie493742.sharepoint.com:/sites/Contoso/Operations/Manufacturing?$select=id (this one you can try on the Graph Explorer.
What you get back in the id is in this format:
{hostname},{spsite.id},{spweb.id}
For more info here is the link to the docs: https://learn.microsoft.com/en-us/graph/api/resources/sharepoint?view=graph-rest-1.0
You don't need to do a Graph API call to get the siteId of the current site. It is available in the PageContext.
In the main class of your webpart you can find it at:
this.context.pageContext.site.id
On classic sites using spPageContextInfo:
(location.host + "," + _spPageContextInfo.siteId + "," + _spPageContextInfo.webId).replace(/[\{\}]/g, "")
Execute the below query in Graph explorer
https://graph.microsoft.com/v1.0/sites/{tenantname}.sharepoint.com:/sites/{sitename}
replace the tenantname and sitename placeholders.
The key 'Id' in the JSON response holds the site Id value
Another way you can get the Site-id by below Graph Http Get API.
https://graph.microsoft.com/v1.0/sites

Resources