Graph API
30 TopicsUnable to create Azure AD user using Graph API
Note I'm somewhat new to using the Graph API, so please forgive me (and correct me) if my terminology is wrong 👍 As I understand, https://docs.microsoft.com/en-us/graph/api/user-post-users documents that it should be possible for an Application to call the API and specifies the required permissions, headers and body to create a new Azure AD user account. Using PowerShell, I've tried a POST to both the v1.0 and beta endpoints with an authorization token that has the appropriate permissions assigned to create a new user account, but in both cases I see the following error: Invoke-RestMethod : The remote server returned an error: (400) Bad Request. The parameters I passed are a variation of those from https://docs.microsoft.com/en-us/graph/api/user-post-users?view=graph-rest-1.0&tabs=http#example-1-create-a-user (with the user principal name amended to have the appropriate suffix for the tenant in question, and a different password). When I run the following try { Invoke-RestMethod -Headers $header -Uri $uri -Method "POST" -Body $userparams -ErrorAction Stop } catch [System.Net.WebException] { if ($_.Exception.Response -eq $null) { throw } $streamReader = [System.IO.StreamReader]::new($_.Exception.Response.GetResponseStream()) $streamReader.BaseStream.Position = 0 $streamReader.ReadToEnd() | ConvertFrom-Json } I see the "(400) Bad Request" error is apparently due to an invalid passwordProfile: @{code=Request_BadRequest; message=Invalid property 'PasswordProfile'.; innerError=} Amending the properties of the passwordProfile object according to https://docs.microsoft.com/en-us/graph/api/resources/passwordprofile?view=graph-rest-1.0 hasn't helped. If I entirely remove the passwordProfile parameter from the body of my POST I get a slight variation on the exception.response inasmuch as it says: @{code=Request_BadRequest; message=A password must be specified to create a new user.; innerError=} Having checked, I am also unable to create a new user account when using a Delegated (work or school account) to call the same API and specify the same headers and body, with the same resulting errors. Note, I am able to create a new user account using https://docs.microsoft.com/en-us/powershell/module/microsoft.graph.users/new-mguser?view=graph-powershell-beta (version https://www.powershellgallery.com/packages/Microsoft.Graph.Users/1.9.2) using exactly the same body parameters, so I have hope that the parameters are defined correctly after all Can anyone help me understand what I need to do to be able to create users using the Graph API, ideally with Application permissions?Solved5.9KViews0likes1CommentError when creating an Office 365 Group with more than 20 members using Graph API
I am getting an error when trying to create an Office 365 Group using Graph API. This only occurs when Group is being provisioned with more than 20 members. Endpoint: POST https://graph.microsoft.com/v1.0/groups Error: A resource cannot contain more than '20' link changes. Anyone know of what this limit is? Can a Group be provisioned with only less than 20 members via the graph api?2.2KViews0likes1CommentSpecify a character set when creating HTML message with Graph
I have an application that creates messages in Microsoft M365 using the Graph API. I use the "body" element with sub-properties "contentType" and "content" to specify the text of the message. When contentType is HTML, the HTML that goes into content is not made by my application, rather it is transferred from an external source, and I don't attempt to modify it in any way. The problem I'm having with one specific message is that it is encoded in ISO-8859-1 instead of UTF8, and M365 will not display the non-English characters correctly. The HTML itself has a META tag that specifies the character set: META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=iso-8859-1\"> And in fact this HTML body looks fine when displayed by itself in a browser window, it's just M365 that screws up the rendering. Is there I way I can tell Graph or M365 what the character set is for this property?1.7KViews0likes0CommentsChange Teams Meeting Options (Who can bypass lobby) via Graph API
I would like to change the who can bypass lobby meeting options of teams meeting via power automate using graph api. So, I checked the meeting options via teams user interface like below first photo. Then I tried to apply this configuration on power automate via graph. So, I checked the documentation of Update Event for Teams meeting as recommended the link following: https://docs.microsoft.com/en-us/graph/api/onlinemeeting-update?view=graph-rest-1.0&tabs=http But there is not any options to restrict the user outside of my organization like the parameter "People in my organization" in the teams meeting options user interface for lobbybyPassSettings parameter. I checked how the lobbybypassSettings gets the value if the who can bypass lobby parameter has been set via teams meeting options user interface via powerautomate. It sets this parameter as "unknownFutureValue". But when I checked the documentation, Microsoft does't recommend this value to set.1.6KViews0likes2CommentsUnable to Export All Channels Conversations from a Team using Graph-PowerShell
I'm using the below script to export channel conversations. It works fine per channel. But I want to be able to export all channel conversations in a Team. I tried using ForEach ($Channel in $Channels) but it's not working. Can someone help please. Credit to PSGuy for the original script: https://www.psguy.eu/how-to-export-ms-teams-chat-to-html-file-for-backup/ [CmdletBinding(DefaultParameterSetName='default')] param ( [Parameter(ParameterSetName='Channel')] $Team, [Parameter(Mandatory=$false,ParameterSetName='default')] [Parameter(Mandatory=$true,ParameterSetName='Channel')] $Channel ) Write-Host "Exporting Team Chats Homie" $scriptpath = $MyInvocation.MyCommand.Path $dir = Split-Path $scriptpath $Date = Get-Date -Format "MM-dd-yyyy-HHmm" $clientId = "YourClientID" $tenantName = "YourTenantName" $clientSecret = "YourClientSecret" $resource = "https://graph.microsoft.com/" $ReqTokenBody = @{ Grant_Type = "Password" client_Id = $clientID Client_Secret = $clientSecret Username = 'YourTeamsAdmUserName' Password = 'YourTeamsAdmPassword' Scope = "https://graph.microsoft.com/.default" } $TokenResponse = Invoke-RestMethod -Uri "https://login.microsoftonline.com/$TenantName/oauth2/v2.0/token" -Method POST -Body $ReqTokenBody #Getting all Groups $apiUrl = "https://graph.microsoft.com/beta/groups" $Data = Invoke-RestMethod -Headers @{Authorization = "Bearer $($TokenResponse.access_token)"} -Uri $apiUrl -Method Get -ErrorVariable RespErr $Groups = ($Data | Select-Object Value).Value if ($Team -eq $NULL){ Write-Host "You have" -NoNewline Write-Host " $($Groups.Count)" -ForegroundColor Yellow -NoNewline Write-Host " teams." Write-Host "" Write-Host "Messages from which Team do you want to export to the HTML format?" -ForegroundColor Yellow $Groups | FT DisplayName,Description $Team = Read-Host "Type one of the Team (DisplayName)" } $TeamID = ($Groups | Where-Object {$_.displayname -eq "$($Team)"}).id $apiUrl = "https://graph.microsoft.com/v1.0/teams/$TeamID/Channels" $Data = Invoke-RestMethod -Headers @{Authorization = "Bearer $($TokenResponse.access_token)"} -Uri $apiUrl -Method Get if ($Channel -eq $NULL){ Write-Host "You choose" -NoNewline Write-Host " $($Team)" -ForegroundColor Yellow -NoNewline Write-Host " Team." Write-Host "" $Channels = ($Data | Select-Object Value).Value Write-Host "Messages from which Channel do you want to export to the HTML format?" -ForegroundColor Yellow $Channels | FT DisplayName,Description $Channel = Read-Host "Type one of the Channel(DisplayName)" } $ChannelID = (($Data | Select-Object Value).Value | Where-Object {$_.displayName -eq "$($Channel)"}).ID $apiUrl = "https://graph.microsoft.com/beta/groups/$TeamID/members" $Data = Invoke-RestMethod -Headers @{Authorization = "Bearer $($TokenResponse.access_token)"} -Uri $apiUrl -Method Get class messageData { [string]$dateTime [string]$from [string]$body messageData() { $this.dateTime = "" $this.from = "" $this.body = "" } } function parseMessage($Data) #returns resultset { $messages = ($Data | Select-Object Value).Value foreach ($message in $Messages) { $messageID = $message.id $messageSet = New-Object System.Collections.ArrayList; $result = New-object messageData #parse message if ($NULL -eq $message.from.user.displayName) { $result.dateTime = $message.createdDateTime $result.from = $message.from.application.displayName } else { $result.dateTime = $message.createdDateTime $result.from = $message.from.user.displayName } $bodyOut = "" if ($NULL -eq $message.summary) { foreach ($attachment in $message.attachments) { $output = $attachment.content $output = $output.substring(14) $output = $output.substring(0,$output.length-4) $bodyOut = $bodyOut + $output } } else { $bodyOut = $message.summary; } $bodyOut = $bodyOut + $message.body.content $result.body = $bodyOut; $messageSet.Add($result) #parse replies $repliesURI = "https://graph.microsoft.com/beta/teams/" + $TeamID + "/channels/" + $ChannelID + "/messages/" + $messageID + "/replies?`$top100" $repliesResponse = Invoke-RestMethod -Method Get -Uri $repliesURI -Headers @{Authorization = "Bearer $($TokenResponse.access_token)"} foreach ($reply in $repliesResponse.value ) { $replyData = New-Object messageData if ($NULL -eq $reply.from.user.displayName) { $replyData.dateTime = $reply.createdDateTime $replyData.from = $reply.from.application.displayName } else { $replyData.dateTime = $reply.createdDateTime $replyData.from = $reply.from.user.displayName } $bodyOut = "" if ($NULL -eq $message.summary) { foreach ($attachment in $reply.attachments) { $output = $attachment.content $output = $output.substring(14) $output = $output.substring(0,$output.length-4) $bodyOut = $bodyOut + $output } } else { $bodyOut = $message.summary } $replyData.body = $bodyOut + $reply.body.content $messageSet.Add($replyData) } $resultList.Add($messageSet) } return } $TokenResponse = Invoke-RestMethod -Uri "https://login.microsoftonline.com/$TenantName/oauth2/v2.0/token" -Method POST -Body $ReqTokenBody $resultList = New-Object System.Collections.ArrayList; $apiUrl = "https://graph.microsoft.com/beta/teams/$TeamID/channels/$ChannelID/messages?`$top=100" $sourceData = Invoke-RestMethod -Headers @{Authorization = "Bearer $($TokenResponse.access_token)"} -Uri $apiUrl -Method Get parseMessage($sourceData) $nextLink = $sourceData.'@Odata.NextLink' while ($NULL -ne $nextLink) { $nextURL = $nextLink; $sourceData = Invoke-RestMethod -Headers @{Authorization = "Bearer $($TokenResponse.access_token)"} -Uri $nextURL -Method Get parseMessage($sourceData) $nextLink = $sourceData.'@Odata.NextLink' } $resultFieldSet = New-Object System.Collections.ArrayList foreach($resultData in $resultList) { $resultFields = $resultData | Select-Object @{Name = 'DateTime'; Expression = {Get-Date -Date (($_).dateTime) -Format 'MM/dd/yyyy hh:mm:ss.fff tt'}}, @{Name = 'From'; Expression = {((($_).from))}}, @{Name = 'Message'; Expression = {(($_).body) -replace '<.*?>',''}}| Sort-Object DateTime $resultFieldSet.Add($resultFields) } $Header = @" <style> h1, h5, th { text-align: center; } table { margin: auto; font-family: Segoe UI; box-shadow: 10px 10px 5px #888; border: thin ridge grey; } th { background: #0046c3; color: #fff; max-width: 400px; padding: 5px 10px; } td { font-size: 11px; padding: 5px 20px; color: #000; } tr { background: #b8d1f3; } tr:nth-child(even) { background: #dae5f4; } tr:nth-child(odd) { background: #b8d1f3; } </style> "@ $count = 0 foreach ($resultCount in $resultList){ $count = $count + $resultCount.Count } $body = "<body><b>Generated:</b> $(Get-Date -Format 'MM/dd/yyyy hh:mm tt') <br><br> <b>Team Name:</b> $($Team) <br> <b>Channel Name:</b> $($Channel) <br><br>" + "<b>number of messages:</b> " + $count + " <br><br>" $body = $body + "</head>" $resultHtml = "" foreach ($resultFields in $resultFieldSet){ $tempHtml = $resultFields | ConvertTo-Html -Head $header $resultHtml = $tempHtml + "<br>" + $resultHtml } $resultHtml = $body + "<br>" + $resultHtml $Export = "$dir\TeamsHistory\$Team-$Channel" New-Item -ItemType Directory -Path $Export -ErrorAction Ignore $resultHtml | Out-File $Export\$Team-$Channel-$Date.html Write-Host " " Write-Host "Messages from the" -NoNewline Write-Host " $($Team)" -NoNewline -ForegroundColor Yellow Write-Host " team and" -NoNewline Write-Host " $($Channel)" -NoNewline -ForegroundColor Yellow Write-Host " channel were generated and saved to the" -NoNewline Write-Host " $($Export)" -NoNewline -ForegroundColor Yellow Write-Host " as a" -NoNewline Write-Host " $($Team)-$($Channel)-$($Date).html" -NoNewline -ForegroundColor Yellow Write-Host " file." Write-Host " "1.3KViews0likes2CommentsAny REST APIs to get security questions of Azure Active Directory user
We have a requirement to get security questions for a user registered on Active Directory. We used graph API(https://graph.microsoft.com/v1.0/users/ {Id})to get users details. However we failed to see security questions in that API response. Request to share any info which programmatically gets and validates user's security questions. Thanks in advance.1.2KViews0likes1CommentUsing Microsoft Graph API on Outlook calendar without checking inside private events
Hi. I have a question on how Microsoft Graph API works when collecting users' private events (only visible to him/herself) from outlook. I'd like to collect sets of occupied time of users' calendars in my organization for automated meeting arrangement, but for private concerns I'm compelled to achieve it without being able to see the contents of private events.(i.e. Meeting title, those involved and description) Such scopes as Calendars.Read allow me to even check inside the private events. Is there any alternative usage on Microsoft Graph API to avoid it to get only occupied time sets? Thank you. c.f. https://docs.microsoft.com/ja-jp/graph/api/calendar-get?view=graph-rest-1.0&tabs=http1.1KViews0likes0CommentsPull Audit and Compliance Data via Microsoft Graph
We have been using reports and dashboards in Microsoft Compliance Center. The big issue on those is that the data is only available and limited for 30 days. We need to pull audit/compliance data such as those we have in https://compliance.microsoft.com/:: a. Microsoft Purview --> Reports: Retention Label Usage, Sensitivity Label Usage, Retention Label Changes, Label trends over the past X days, DLP Policy Matches, DLP Incidents, DLP false positives and overrides, plus b. those we have in Microsoft Purview --> Reports --> Activity Explorer but for more than 30 days, for any date range we wish to pull the data for and have a report. I would like to know if with Microsoft Graph we can pulling this information via Graph, and then feed it into some PowerBi Dashboard. Any help or directions if you ever had such experience, solution is appreciated. Ali1.1KViews0likes1CommentPlease tell me how to get the URL of the file in the event.
Please tell me how to get the URL of the file in the event using graph api. It is the following file. The file was shared via chat during a video conference. When I executed the API referring to the link below, the file could not be obtained. https://docs.microsoft.com/ja-jp/graph/api/event-list-attachments?view=graph-rest-1.0&tabs=http GET /me/events/AAMkADA1ZjgxYzIzLTQyNWUtNDI3Mi04YjJhLWJiMjliZDI4ZDlhZABGAAAAAADqjBSo05aEQa0pg3g68HfIBwCG7IUHTsMnQqpuCmPLOpmMAAAAAAENAACG7IUHTsMnQqpuCmPLOpmMAAA7Kcf_AAA=1KViews0likes0CommentsMicrosoft graph api error, mail fetching error
Mail fetching error Endpoint https://graph.microsoft.com/v1.0/me/messages?$select=sender,subject,toRecipients,ccRecipients,bccRecipients,createdDateTime&top=50 Action: After fetching mails with pagination, for some random user at a random time, it fails with 503 Service Unavailable. Some times it fails for specific user other time it works. Additional Info Failed response headers ```{ 'strict-transport-security': 'max-age=31536000', 'request-id': '012dc140-42b5-4fa2-851d-b46a1f206b84', 'client-request-id': '012dc140-42b5-4fa2-851d-b46a1f206b84', 'x-ms-ags-diagnostic': '{"ServerInfo":{"DataCenter":"West US","Slice":"E","Ring":"4","ScaleUnit":"001","RoleInstance":"BY1PEPF00006DD7"}}', date: 'Thu, 13 Oct 2022 15:26:07 GMT', connection: 'close', 'content-length': '0' }```838Views0likes0Comments