r/GraphAPI • • Aug 20 '23

Getting user sign in attempt success/failure state

2 Upvotes

Hi, This morning when I was messing around with graph api data, i saw a lastsign in date filled out for last week on a disabled user account (mailbox account which is disabled for a long time). It showed last login date (?!) sign in state however showed as "failed" in the azure portal .. For this reason I am looking for a way to get the sign in state for successfull login or failed login. The only method I found so far is to loop through signinauditlog for the last sign in attempt for each user.. but this takes more then 5hours for 6000+ accounts .. has anyone found a better method for this ?


r/GraphAPI • • Jul 19 '23

Anyone got any experience setting Sharepoint site permissions using Graph API?

2 Upvotes

When we signed a new client, our old method was to create a folder on our file server named after the client, and to create an security group with modify permissions on said folder.

I've been tasked with moving this process into sharepoint and to script the process so it happens automatically as part of our 'project creation' Jenkins job.

I've used Python and Graph API and managed to successfully create the sharepoint and the security group. I just can't then assign the permissions and can't see any instructions online. I can see instructions on how to view access control lists, but not how to set them.

I've searched the internet and haven not found a solution! Not helpful that when I search graph API site permissions it assumes you're talking about the permission of your Azure app. Chat GPT wasn't much helpful either.

Has anyone got any experience of this or am I going to have to use another module (not ideal as feels unclean and will probably also mean updating our Jenkins workers which is a pain)


r/GraphAPI • • Jul 19 '23

Get-MgDomain : Insufficient privileges to complete the operation.

2 Upvotes

I am trying to run this script:

$AutopilotProfiles = Get-AutopilotProfile

Foreach ($AutopilotProfile in $AutopilotProfiles) {

$TempPath = "C:\ProgramData\OSDCloud\Config\AutopilotJSON\"

if (!(Test-Path $TempPath)) {

New-Item -Path $TempPath -ItemType Directory -Force

}

$name = $AutopilotProfile.displayName

$ExportPath = $TempPath + $name + "_AutopilotConfigurationFile.json"

$AutopilotProfile | ConvertTo-AutopilotConfigurationJSON | Out-File $ExportPath -Encoding ASCII

}

I get the following error. How do I grant permission to be able to run this script?

Get-MgDomain : Insufficient privileges to complete the operation.

Status: 403 (Forbidden)

ErrorCode: Authorization_RequestDenied

Date: 2023-07-19T16:32:59

Headers:

Transfer-Encoding : chunked

Vary : Accept-Encoding

Strict-Transport-Security : max-age=31536000

request-id : 262f828c-80d7-4556-88b8-d2617a951d85

client-request-id : 1475fe7b-dbb8-4b9b-8fe8-eae79ca582e5

x-ms-ags-diagnostic : {"ServerInfo":{"DataCenter":"North Central

US","Slice":"E","Ring":"3","ScaleUnit":"003","RoleInstance":"CH01EPF0001E922"}}

x-ms-resource-unit : 1

Cache-Control : no-cache

Date : Wed, 19 Jul 2023 16:32:58 GMT

At C:\Program Files\WindowsPowerShell\Modules\windowsautopilotintune\5.6\WindowsAutoPilotIntune.psm1:587 char:5

+ $script:allDomains = Get-MgDomain -All

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ CategoryInfo : InvalidOperation: ({ Top = , Skip ...ndProperty = }:<>f__AnonymousType21`8) [Get-MgDoma

in_List], Exception

+ FullyQualifiedErrorId : Authorization_RequestDenied,Microsoft.Graph.PowerShell.Cmdlets.GetMgDomain_List

Get-MgDomain : Insufficient privileges to complete the operation.

Status: 403 (Forbidden)

ErrorCode: Authorization_RequestDenied

Date: 2023-07-19T16:32:59

Headers:

Transfer-Encoding : chunked

Vary : Accept-Encoding

Strict-Transport-Security : max-age=31536000

request-id : d81bd90f-47c1-4536-b3f6-4b3c96cbb8b7

client-request-id : d90d7bb0-d5a1-44bf-a740-df56fb8d839a

x-ms-ags-diagnostic : {"ServerInfo":{"DataCenter":"North Central

US","Slice":"E","Ring":"3","ScaleUnit":"003","RoleInstance":"CH01EPF0000C15D"}}

x-ms-resource-unit : 1

Cache-Control : no-cache

Date : Wed, 19 Jul 2023 16:32:59 GMT

At C:\Program Files\WindowsPowerShell\Modules\windowsautopilotintune\5.6\WindowsAutoPilotIntune.psm1:587 char:5

+ $script:allDomains = Get-MgDomain -All

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ CategoryInfo : InvalidOperation: ({ Top = , Skip ...ndProperty = }:<>f__AnonymousType21`8) [Get-MgDoma

in_List], Exception

+ FullyQualifiedErrorId : Authorization_RequestDenied,Microsoft.Graph.PowerShell.Cmdlets.GetMgDomain_List

Get-MgDomain : Insufficient privileges to complete the operation.

Status: 403 (Forbidden)

ErrorCode: Authorization_RequestDenied

Date: 2023-07-19T16:32:59

Headers:

Transfer-Encoding : chunked

Vary : Accept-Encoding

Strict-Transport-Security : max-age=31536000

request-id : eeb29bbf-5171-4673-ad14-d1e4a8fa8327

client-request-id : a1ad1872-911a-483d-875e-8172bd733c41

x-ms-ags-diagnostic : {"ServerInfo":{"DataCenter":"North Central

US","Slice":"E","Ring":"3","ScaleUnit":"003","RoleInstance":"CH01EPF00025EDC"}}

x-ms-resource-unit : 1

Cache-Control : no-cache

Date : Wed, 19 Jul 2023 16:32:58 GMT

At C:\Program Files\WindowsPowerShell\Modules\windowsautopilotintune\5.6\WindowsAutoPilotIntune.psm1:587 char:5

+ $script:allDomains = Get-MgDomain -All

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ CategoryInfo : InvalidOperation: ({ Top = , Skip ...ndProperty = }:<>f__AnonymousType21`8) [Get-MgDoma

in_List], Exception

+ FullyQualifiedErrorId : Authorization_RequestDenied,Microsoft.Graph.PowerShell.Cmdlets.GetMgDomain_List

Get-MgDomain : Insufficient privileges to complete the operation.

Status: 403 (Forbidden)

ErrorCode: Authorization_RequestDenied

Date: 2023-07-19T16:33:00

Headers:

Transfer-Encoding : chunked

Vary : Accept-Encoding

Strict-Transport-Security : max-age=31536000

request-id : 56c78b5d-8159-405d-8aa8-41a9417feb0b

client-request-id : d076d0d7-345d-438e-8f8c-1d86a598e0b4

x-ms-ags-diagnostic : {"ServerInfo":{"DataCenter":"North Central

US","Slice":"E","Ring":"3","ScaleUnit":"003","RoleInstance":"CH01EPF00025EEA"}}

x-ms-resource-unit : 1

Cache-Control : no-cache

Date : Wed, 19 Jul 2023 16:32:59 GMT

At C:\Program Files\WindowsPowerShell\Modules\windowsautopilotintune\5.6\WindowsAutoPilotIntune.psm1:587 char:5

+ $script:allDomains = Get-MgDomain -All

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ CategoryInfo : InvalidOperation: ({ Top = , Skip ...ndProperty = }:<>f__AnonymousType21`8) [Get-MgDoma

in_List], Exception

+ FullyQualifiedErrorId : Authorization_RequestDenied,Microsoft.Graph.PowerShell.Cmdlets.GetMgDomain_List


r/GraphAPI • • Jul 05 '23

Getting a full Graph collection into Postman

2 Upvotes

Hello, I already have the postman collection for Microsoft Graph forked and working (https://www.postman.com/microsoftgraph/workspace/microsoft-graph/collection/455214-085f7047-1bec-4570-9ed0-3a7253be148c/fork)

All of the requests are working as intended, but I'm noticing that even though there's quite a bit, there isn't much in terms of Security requests. For instance, I want to bulk dismiss Risk Users. So at first I just thought Microsoft didn't have a request for that. But then I found this - https://learn.microsoft.com/en-us/graph/api/riskyuser-dismiss?view=graph-rest-1.0&tabs=http

So I made a custom request with it, and it worked in Postman. So the official postman collection for microsoft graph seems to have about 1% of what is really possible in Graph.

I guess what I think my question is... how can I get everything in here (https://learn.microsoft.com/en-us/graph/api/overview?view=graph-rest-1.0) into Postman?

Thank you!


r/GraphAPI • • Jun 20 '23

Least permission setup with Graph

2 Upvotes

Hi guys,
We have an AAD connector that needs to be able to see users, groups and computers for an organization. It's currently set up with the Directory.Read.All permission - but I'm wondering if this is strict enough.
The Microsoft documentation isn't all that helpful as it just states that " Allows the app to read data in your organization's directory, such as users, groups and apps."
Would it be more correct to set our app up with Users.Read.All, Devices.Read.All and Groups.Read.All - or does this actually cover exactly what the Directory.Read.All does?

Thanks a lot :)


r/GraphAPI • • Jun 09 '23

Where does the 'from' user field get set from when using Graph API for 'Send chatMessage in channel' but the from field isn't specified in the request body?

2 Upvotes

We are setting up an automation to send a message to a Microsoft Teams channel using an app to integrate with Graph API. We are able to send the message successfully however, we are looking to adjust who the message comes from. Unfortunately we are using an integration that doesn't allow additional fields to be set outside of Teams ID, channel ID, and the message body. Does anyone know how the api determines who the message should come from if it isn't specified in the POST request?

We have attempted updating the owner of the app in Azure but no change. Suspecting it might be the user who authorized the app but we haven't been able to test with the other team.


r/GraphAPI • • Apr 22 '23

Compliance assessments

2 Upvotes

I am trying to find some way to access the compliance reports and assessments in purview. I have seen a few very very short learn articles that may imply that are there, but I can't find them.

My goal is to integrate our doc as code + OSCAL models to populate the compliance narratives in purview. (And vice versa, Microsoft met controls into OSCAL documents.


r/GraphAPI • • Apr 07 '23

Creating an Azure Function using Microsoft Graph API

Thumbnail
link.medium.com
2 Upvotes

I have written an article on the implementation of Azure Functions using Microsoft Graph API. Feel free to read, share and comment.


r/GraphAPI • • Apr 03 '23

Azure enterprise app - set Linked-based signon-url via powershell?

2 Upvotes

looking to do this https://learn.microsoft.com/en-us/azure/active-directory/manage-apps/configure-linked-sign-on

but via powershell, graph SDK. or even graph api. does anyone know how to set this value? nothing online that i can find


r/GraphAPI • • Mar 18 '23

OR Condition in Graph API

2 Upvotes

I am trying to run OR condition to find users with either of license assigned but its not working. Can someone please help to correct it ?

https://graph.microsoft.com/v1.0/users?$filter=assignedLicenses/any(x:x/skuId eq '18181a46-0d4e-45cd-891e-60aabd171b4e' or x/skuId eq '06ebc4ee-1bb5-47dd-8120-11324bc54e06')


r/GraphAPI • • Feb 27 '23

Get Intune device information (Serial)

2 Upvotes

I have been searching and reading for solutions to what I am looking for with no avail.
I am looking to get a list of Intune devices serial information from graph using PowerShell or rest method.
Is there any call that I can obtain the devices serial?


r/GraphAPI • • Feb 25 '23

Get all past callRecords and onlineMeetings of the past month

2 Upvotes

It seems that it's possible to get single records (i.e. GET /me/onlineMeetings/{meetingId} or GET https://graph.microsoft.com/v1.0/communications/callRecords/{id}) but how could someone get the IDs?

Let's say I want all of my records of the past week or the past month. There must be some way, right?

In the end I just want to have a possibility to see for how long I had meetings and calls with whom. So I basically want to see if who spontaneously called two weeks ago and that the call went 45 minutes.


r/GraphAPI • • Feb 20 '23

C# SDK Graph API batching device (issues with working with returned data)

2 Upvotes

I am having issues with the C# SDK when reading the data back from the batching calls. I can't find an excellent way to get it into the Graph API device object (collection, list, array. or something I can work with)
tried to give things like. No joy on any of these

var devices = await returnedResponse.GetResponseByIdAsync<Device>(deviceReuestID);

var deviceList = await returnedResponse.GetResponseByIdAsync<List<Device>>(deviceReuestID); var deviceIcollection = await returnedResponse.GetResponseByIdAsync<IGraphServiceDevicesCollectionRequest>(deviceReuestID);

I'm using Microsoft.Graph.Beta version 4.44.0-preview (as at the time of writing this code last year I needed things that were not in none beta version of the SDK and/or API)


r/GraphAPI • • Feb 20 '23

Error when creating subscription to change notifications

2 Upvotes

I am currently working on a project in Zoho Deluge language. When I an trying to subscribe to change notifications, I am facing an error saying

"error": {

  • "code": "InvalidRequest",

  • "message": "Subscription validation request failed. Response must exactly match validationToken query parameter."
    }

I am passing the exact parameter that I am getting as response, but it still shows this error.How can I solve this issue?


r/GraphAPI • • Feb 07 '23

assignLicense for devices?

2 Upvotes

Have gone through the Graph API reference list and seems you can only assign licenses for users? How about devices? There are several Azure AD Licenses that are device based.

POST https://graph.microsoft.com/v1.0/users/UPN/assignLicense


r/GraphAPI • • Jan 29 '23

Create Mail Folder

2 Upvotes

Hello All,

I am trying to create a MailFolder within a folder using the Graph API. I can get it to create it in the root using the documentation below, but is there a way to get it to create a folder within a folder?

https://learn.microsoft.com/en-us/graph/api/user-post-mailfolders?view=graph-rest-1.0&tabs=http

Many thanks!


r/GraphAPI • • Jan 18 '23

How Do You Create a JSWT To Access MSGRPAH Using Certificate Based Authentication in PowerShell???????

2 Upvotes

Hello All,

The title basically says it all, but I will expand. We are looking to automate some workloads via PowerShell in Azure AD and want to leverage the GraphAPI.

I create am able to automate the connection by using Certificate based authentication I created following this guide. We create the connection like this.

$AppId = "90cb4cab-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

$TenantId = "95cb1f18-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

$Certificate = Get-ChildItem Cert:\CurrentUser\My0CE345F9XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Connect-Graph -TenantId $TenantId -AppId $AppId -Certificate $Certificate

Once connected we are able to run commands via the Microsoft Graph SDK. Simple commands like Get-MgGroup, Get-MgGroupTransitiveMember etc work just fine.

I would like to now expand and start to expand and use the Invoke-WebRequest command in PowerShell so I am not limited to the commands available in the SDK. I am struggling to create the JWT to query get the access to run the commands

Here is the commands I am trying to use to create the JWT

# Get the certificate from the certificate store

$store = New-Object System.Security.Cryptography.X509Certificates.X509Store("MY", "LocalMachine")

$store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadOnly)

$cert = $store.Certificates | Where-Object { $_.Subject -eq "CN=your_certificate_name" }

# Build the JWT assertion

$header = @{alg="RS256";typ="JWT"}

$payload = @{iss="your_client_id";sub="your_client_id";aud="https://graph.microsoft.com";exp=(Get-Date).AddMinutes(10).ToUnixTime()}

$headerEncoded = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(($header | ConvertTo-Json)))

$payloadEncoded = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(($payload | ConvertTo-Json)))

$data = "{0}.{1}" -f $headerEncoded, $payloadEncoded

$signature = [System.Convert]::ToBase64String($cert.GetRSAPrivateKey().SignData(([Text.Encoding]::UTF8.GetBytes($data)), "SHA256"))

$jwt = "{0}.{1}.{2}" -f $headerEncoded, $payloadEncoded, $signature

# Make the request to the Microsoft Graph API

$response = Invoke-WebRequest -Method GET -Uri "https://graph.microsoft.com/v1.0/users?$select

And here is the query I am trying to run that fails.

$response = Invoke-WebRequest -Method GET -Uri "https://graph.microsoft.com/v1.0/users?$select=userPrincipalName" -Headers @{Authorization = "Bearer $jwt"}

Every time I get the following

Invoke-WebRequest : The remote server returned an error: (401) Unauthorized.

Any help or guidance is appreciated! Am I even close?

Thanks!


r/GraphAPI • • Jan 10 '23

Is there a way to check if a user has access to certain groups without having the correct access packages assigned?

2 Upvotes

Hi guys

I'm currently looking into case for a client where they'd like to check if there are users that have access to certain AD Groups without the proper assigned Access Packages.

I've been looking everywhere at AssignmentPolicies, AssignmentRequests, Access Package Resources, but the main thing that eludes me is how to connect Access Packages and Groups.

Is this doable? Anyone that's already done this?

Thanks!


r/GraphAPI • • Dec 23 '22

Microsoft Graph Group Delta

2 Upvotes

Hey Guys,

Is is possible to get changes(user added/removed) to an ad group using Microsoft graph delta query? if yes can anyone share powershell script to get the information?

Thx,PRS


r/GraphAPI • • Dec 21 '22

Teams Rooms get all Calls/Meetings?

2 Upvotes

I am looking for a way to get all the calls a Teams Room has done. I can pull calendar events and get all the scheduled meetings a room has done. That was pretty strait forward. However, Teams Rooms can do ad-hoc Meetings as well as Calls. So to get a full picture on what the MTR is doing, I would like to get those non-scheduled items as well.

I have looked in the API at Get Call: https://learn.microsoft.com/en-us/graph/api/call-get?view=graph-rest-beta&tabs=http

However, you need the Call ID to pull a call object. I don't have the Call ID. Is there a way to get all the Call ID's from a user account?

Teams Admin Center will show all of a users calls (pretty sure at least), but we have 100+ devices and I would like to pull that info via Graph as it would be way easier.


r/GraphAPI • • Dec 12 '22

Adding app permissions

2 Upvotes

I have an app that have permissions to read users and CRUD for events.
And want to add read emails.

Does the current organizations that have consented the old permissions need to consent again when i add new ones?
Will their events still work while waiting for new consent?

Would it be better to register the email calls as a new app?


r/GraphAPI • • Dec 02 '22

Access denied for Groups

2 Upvotes

I am attempting to use Graph Client to get groups and members. I have the application set up in AD with the proper permissions. However, when I attempt to get the groups, it comes up with access denied. The code works when I use a user Id to get emails. The code to get the client is:

            var scopes = new string[] { "https://graph.microsoft.com/.default" };

            IConfidentialClientApplication confidentialClient = ConfidentialClientApplicationBuilder
                .Create(clientId)
                .WithClientSecret(secretValue)
                .WithTenantId(tenantId)
                .Build();

            // Retrieve an access token for Microsoft Graph (gets a fresh token if needed).
            var authResult = await confidentialClient
                    .AcquireTokenForClient(scopes)
                    .ExecuteAsync().ConfigureAwait(false);

            var token = authResult.AccessToken;

            GraphServiceClient graphServiceClient =
                new(new DelegateAuthenticationProvider(async (requestMessage) =>
                {
                    requestMessage.Headers.Authorization =
                            new AuthenticationHeaderValue("Bearer", token);
                })
                );

The code to get groups is simple:

 var groups = await graphClient
                    .Groups
                    .Request()
                    .GetAsync();

The permissions have been granted to the application:

What am I doing wrong?


r/GraphAPI • • Oct 28 '22

Logic App Using Graph API to get Drive File Contents

2 Upvotes

In order to use Managed Identities in our logic app we are using Graph API. Everything is working great, (moving files from email to SharePoint Doc Lib, uploading files from on-prem into SharePoint, etc.) however I can't seem to figure out how to get the contents of a file in the JSON response of the body. Everytime I append "/content" to the end of the URL it tries downloading the file. I'm looking for a way to get the contentBytes returned in the body of a JSON response like I do when I get attachments of emails. The HTTP graph API call in the logic app gets a 302(redirect) because it tries downloading the file. I can't find anything that helps me in the Microsoft Graph API documentation either, if anyone has any information that could help me get the byte contents as a JSON response that would be great, thanks!


r/GraphAPI • • Oct 24 '22

Is there a way to use GraphAPI to get logged in AzureAD Accounts on a managed device, not just local accounts?

2 Upvotes

A Windows device that is AAD joined. I would like to be able to query it locally and retrieve not just the local accounts on the system, but the currently logged-in Azure AD account (and others that have logged into the device as well)

Is this possible?