How to Generate Intune Device Inventory Report using Graph API

This post will explain how to Generate Intune Device Inventory report using Microsoft Graph API and provide insights into the process of developing the code to automate the Microsoft Intune Device Inventory report through Microsoft Graph API.

Microsoft Intune offers a wide range of reports within the admin center, which can be exported using Graph APIs. Microsoft Graph, a RESTful web API, facilitates access to Microsoft Cloud service resources. To export Intune reports, utilising the Microsoft Graph API to execute a sequence of HTTP calls is imperative.

Microsoft Graph is an API that lets you access data, intelligence, and insights from Microsoft 365 and other Microsoft Cloud services through a single endpoint. This includes Microsoft 365, Windows, and Enterprise Mobility + Security data.

This Microsoft Graph API is designed to perform the same range of Intune operations as those available through the Azure Portal. By using Microsoft Graph, developers can build intelligent applications that leverage the power of Microsoft 365 and other Microsoft services to enhance productivity and collaboration.

Patch My PC
[sibwp_form id=2]

Know more about Application Programming Interface (API)?

What is an API? You should know a little more about API before doing any Microsoft Graph automation. The API stands for Application Programming Interface. In the context of APIs, the term Application refers to any software with a distinct function. The Interface can be considered as a service contract between two applications.

How to Generate Intune Device Inventory Report using Graph API Fig. 1
How to Generate Intune Device Inventory Report using Graph API Fig. 1

APIs are tools that allow two software components to communicate with each other using a defined set of protocols and definitions. API architecture is often described in terms of a client and a server. The software that initiates the request is the client, and the software that sends the response is the server.

Notably, four types of API protocols are available: SOAP, RCP, WebSocket, and REST APIs. SOAP APIs use Simple Object Access Protocol, where the client and server exchange XML messages. RCP APIs, or Remote Procedure Calls, allow the client to execute a function or procedure on the server, with the server sending the output back to the client. 

WebSocket API is a modern web API development that uses JSON objects to pass data. REST APIs, representing Representational State Transfer, define a set of functions, such as GET, PUT, POST, DELETE, etc., that clients can use to access server data, where Clients and servers exchange data using HTTP.

Adaptiva

Generate Intune Device Inventory Report using Microsoft Graph API

Let’s learn how to Export Data for all Managed Devices using Graph API. I will use Graph Explorer, a handy browser-based tool for running your Graph calls. The tool does not support batch commands and is limited to executing single-line commands. API calls are made through the Graph Explorer. Upon accessing the Graph Explorer, a webpage like the one below will be displayed.

NOTE! You may need to log in to Graph Explorer using your credentials if it's your first time. 

You can use the Microsoft Graph API endpoint provided below to export reports in Microsoft Intune. Your request must use the POST HTTP method.

https://graph.microsoft.com/beta/deviceManagement/reports/exportJobs

You must provide a reportName parameter as part of the request body based on the report that you would like to export using Microsoft Graph API. Use DeviceCompliance as reportName in this example. Microsoft has documented the possible values for the reportName.

The table below contains the available properties of the DevicesWithInventory report. These property values will have the output of your relevant columns. Thank you, Microsoft, for providing the detailed table.

Requestable ColumnsColumns received
DeviceIdDevice ID
DeviceNameDevice name
CreatedDateEnrollment date
LastContactLast check-in
ReferenceIdMicrosoft Entra Device ID
OSVersionOS version
GraphDeviceIsManagedMicrosoft Entra registered
EasIDEAS activation ID
SerialNumberSerial number
ManufacturerManufacturer
ModelModel
EasActivationStatusEAS activated
IMEIIMEI
EasLastSyncSuccessUtcLast EAS sync time
EasStateReasonEAS reason
EasAccessStateEAS status
InGracePeriodUntilCompliance grace period expiration
AndroidPatchLevelSecurity patch level
WifiMacAddressWi-Fi MAC
MEIDMEID
SubscriberCarrierNetworkSubscriber carrier
StorageTotalTotal storage
StorageFreeFree storage
ManagedDeviceNameManagement name
CategoryNameCategory
UserIdUserId
UPNPrimary user UPN
UserEmailPrimary user email address
UserNamePrimary user display name
WiFiIPv4AddressWiFiIPv4Address
WiFiSubnetIDWiFiSubnetID
CompliantState (alias: ComplianceState)Compliance
ManagementAgentManaged by
OwnerTypeOwnership
ManagementStateDevice state
DeviceRegistrationStateIntune registered
IsSupervisedSupervised
IsEncryptedEncrypted
DeviceType (alias: OS)OS
SkuFamilySkuFamily
JoinTypeJoinType
PhoneNumberPhone number
JailBrokenJailbroken
ICCIDICCID
EthernetMACEthernetMAC
CellularTechnologyCellularTechnology
ProcessorArchitectureProcessorArchitecture
EIDEID
EnrollmentTypeEnrollmentType
PartnerFeaturesBitmaskPartnerFeaturesBitmask
ManagementAgentsManagementAgents
CertExpirationDateCertExpirationDate
IsManagedIsManaged
SystemManagementBIOSVersionSystemManagementBIOSVersion
TPMManufacturerIdTPMManufacturerId
TPMManufacturerVersionTPMManufacturerVersion
How to Generate Intune Device Inventory Report using Graph API Table. 1
  • Sign in to the Graph Explorer, paste the Microsoft Graph API endpoint.
NOTE! The tenant must have an active Intune license to use the Microsoft Graph API for Intune. The Microsoft Graph API controls access to resources via permissions. You must specify the permissions you need to access Intune resources. 

https://graph.microsoft.com/beta/deviceManagement/reports/exportJobs

You must supply the request body to execute the task. The request body should have the property details you want to export. I added only a few properties in this example. Use the JSON body below and Click on Run query.

{
    "reportName": "DevicesWithInventory",
    "format": "csv",
    "localizationType": "LocalizedValuesAsAdditionalColumn",
    "select": [
        "DeviceName",
        "DeviceId",
        "OSVersion",
        "CreatedDate",
        "SerialNumber",
        "Manufacturer",
        "Model",
        "StorageTotal",
        "StorageFree",
        "UserName"
    ]
}

As per Microsoft, you can set five main parameters in the request body when making an export request. I have listed those parameters in the table below

How to Generate Intune Device Inventory Report using Graph API Fig. 2
How to Generate Intune Device Inventory Report using Graph API Fig. 2
Parameters Description
reportNameRequired. This parameter is the name of the report you want to specify
filterThis is not required for most reports. Note that the filter parameter is a string
selectThis is not required. Specify which columns from the report you want. Only valid column names relevant to the report you are calling will be accepted.
formatNot required. By default, the data is output in csv format. Specify json to output the file in JSON format.
localizationTypeThis parameter controls localization behavior for the report. Possible values are LocalizedValuesAsAdditionalColumn and ReplaceLocalizableValues.
How to Generate Intune Device Inventory Report using Graph API Table. 2

Well, once you click on the Run Query button, the Graph returns a response message. The response message includes the requested data or the operation’s result.

{
    "@odata.context": "https://graph.microsoft.com/beta/$metadata#deviceManagement/reports/exportJobs/$entity",
    "id": "DevicesWithInventory_3c2b9209-3111-4a66-89a9-b9a861f9a473",
    "reportName": "DevicesWithInventory",
    "filter": null,
    "select": [
        "DeviceName",
        "DeviceId",
        "OSVersion",
        "CreatedDate",
        "SerialNumber",
        "Manufacturer",
        "Model",
        "StorageTotal",
        "StorageFree",
        "UserName"
    ],
    "format": "csv",
    "snapshotId": null,
    "localizationType": "localizedValuesAsAdditionalColumn",
    "search": null,
    "status": "notStarted",
    "url": null,
    "requestDateTime": "2024-06-03T09:08:42.2766322Z",
    "expirationDateTime": "0001-01-01T00:00:00Z"
}
How to Generate Intune Device Inventory Report using Graph API Fig. 3
How to Generate Intune Device Inventory Report using Graph API Fig. 3

You must note down the id field.! To retrieve the status of the export, it is recommended to query the id field using a GET request. The id value must be added in the URL within single quotes (‘id’) as below. Paste the below Microsoft Graph API endpoint and Click on the Run Query

https://graph.microsoft.com/beta/deviceManagement/reports/exportJobs(‘DevicesWithInventory_3c2b9209-3111-4a66-89a9-b9a861f9a473’)

How to Generate Intune Device Inventory Report using Graph API Fig. 4
How to Generate Intune Device Inventory Report using Graph API Fig. 4

You will need to call this Microsoft Graph API endpoint repeatedly until you receive a response containing the status: completed attribute that looks like the example provided

{
    "@odata.context": "https://graph.microsoft.com/beta/$metadata#deviceManagement/reports/exportJobs/$entity",
    "@microsoft.graph.tips": "Use $select to choose only the properties your app needs, as this can lead to performance improvements. For example: GET deviceManagement/reports/exportJobs('<key>')?$select=expirationDateTime,filter",
    "id": "DevicesWithInventory_3c2b9209-3111-4a66-89a9-b9a861f9a473",
    "reportName": "DevicesWithInventory",
    "filter": null,
    "select": [
        "DeviceName",
        "DeviceId",
        "OSVersion",
        "CreatedDate",
        "SerialNumber",
        "Manufacturer",
        "Model",
        "StorageTotal",
        "StorageFree",
        "UserName"
    ],
    "format": "csv",
    "snapshotId": null,
    "localizationType": "localizedValuesAsAdditionalColumn",
    "search": null,
    "status": "completed",
    "url": "https://amsuc0201repexpstorage.blob.core.windows.net/389f73fc-ca4e-4406-b620-78f752ed3a9a/DevicesWithInventory_3c2b9209-3111-4a66-89a9-b9a861f9a473.zip?sv=2019-07-07&sr=b&sig=0ViNgXuza1AWORIAmGlWx4eqzqTNl7FUNVdjyxzEeSE%3D&skoid=c6d6232f-09e2-4da5-975f-c79ae6fa70c2&sktid=975f013f-7f24-47e8-a7d3-abc4752bf346&skt=2024-06-03T09%3A21%3A55Z&ske=2024-06-03T15%3A17%3A28Z&sks=b&skv=2019-07-07&se=2024-06-03T15%3A17%3A28Z&sp=r",
    "requestDateTime": "2024-06-03T09:08:42.2766322Z",
    "expirationDateTime": "2024-06-03T15:17:28.060565Z"
}

You will also get a url in the response. This URL should have the compressed CSV report.

How to Generate Intune Device Inventory Report using Graph API Fig. 5
How to Generate Intune Device Inventory Report using Graph API Fig. 5

You can then directly download the compressed CSV from the URL field. The report should have Intune Device Inventory details as below.

How to Generate Intune Device Inventory Report using Graph API Fig. 6
How to Generate Intune Device Inventory Report using Graph API Fig. 6

I trust that this article will greatly benefit you and your organization. Thank you for being so patient in reading this post. I look forward to seeing you in the next post. Keep supporting the HTMD Community.

We are on WhatsApp now. To get the latest step-by-step guides, news, and updates, Join our Channel. Click here. HTMD WhatsApp.

Author

About the Author – Sujin Nelladath has over 10 years of experience in SCCM device management and Automation solutions. He writes and shares his experiences with Microsoft device management technologies, Azure, and PowerShell automation.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.