Graph Explorer Query: The hack

In this short post we will see an easy hack to find a desired query to be used in graph explorer using the Intune portal.

Scenario

Many times administrators want to query information regarding Intune data from Graph explorer itself. They may want to see the data directly in the Graph Explorer, which includes sometimes more information that the Intune Portal, or prepare a query to be used in a PowerShell script.

Before moving forward let’s explore what is Graph Explorer and Graph API.

Microsoft Graph API is a RESTful web API that enables us to access Microsoft Cloud service resources, such as users, devices, messages, calendars, and more. We can use the Microsoft Graph API to connect to data and other datasets to derive insights and analytics, extend Microsoft 365 experiences, and build intelligent apps. To use the Microsoft Graph API, we can register an app and get authentication tokens for a user or service or directly execute a query in Graph Explorer tool to try the Microsoft Graph APIs in your browser without writing any code (check below for detailed description). Then we can make requests to the Microsoft Graph API using HTTP methods, such as GET, POST, PATCH, PUT, and DELETE.

Microsoft Graph Explorer is a web application that lets us learn about Microsoft Graph APIs. We can use it to try the APIs on the default sample tenant to explore capabilities, or sign in to our own tenant and use it as a prototyping tool to fulfill our app scenarios.

Some of the features of Microsoft Graph Explorer are:

  • We can run GET, POST, PUT, PATCH, and DELETE requests to the Microsoft Graph API and see the responses in real time.
  • We can view and modify the request headers, body, and permissions for each request.
  • We can access code snippets (C#, Java, JavaScript, Go and PowerShell), Microsoft Graph Toolkit components, and adaptive cards for your queries.

In any case, the query to fetch the desired data is needed. Although Microsoft provides documentation that can be used to construct it, there is a very convenient way to extract it directly from Intune Portal.

How to find the Graph Explorer Query?

To find the desired query we would need to use the Developer Tools in the browser that we are using. In this example the Firefox browser will be used.

Graph Explorer Query: The hack

After enabling the developer tools, we need to navigate to the network tab.

Now that we have everything ready let’s see how can we find the Graph Explorer Query from here.

Let’s say that we want to get a list of all Windows 10 devices that exist in Intune. First we have to navigate to Intune in the All Devices blade.

Before selecting Windows devices we need to have the Network tab in the Developer Tools open. After selecting Windows we will see a record in the Network tab indicating a query to the Graph API.

Graph API is the foundation of every information we see in Intune. Intune uses Graph API in the back end to fetch the requested information.

If we right click on the line that contains the desired query, we can copy it and paste it on the Graph Explorer. We can also copy the query as PowerShell and use it later in our custom PowerShell scripts.

Running this query on the Graph Explorer fetches the wanted data.

Although this is a good trick to use, the copied query may sometimes not work properly when used in a PowerShell script.

References and documentation:

Check the below posts to find out more interesting relevant topics:

Leave a Reply

Your email address will not be published. Required fields are marked *