1
votes

To get the Compliance Policy Settings in Intune, we need to use the below api (reference):

Request URL: https://graph.microsoft.com/beta/deviceManagement/settings

Request Method: GET

I can run the api and get the details using Postman, however im struggling to get the API running using Microsoft Graph (Beta) in Java.

Example : Im using the below code snipped for fetching all the compliance policies using microsoft graph beta api:

List<DeviceCompliancePolicy> allDeviceCompliancePolicies = new ArrayList<DeviceCompliancePolicy>();
            DeviceCompliancePolicyCollectionPage deviceCompliancePolicyCollectionPage = this.graphClient
                    .getGraphServiceClient().deviceManagement().deviceCompliancePolicies().buildRequest()
                    .expand("assignments,scheduledActionsForRule($expand=scheduledActionConfigurations)").get();

            while (deviceCompliancePolicyCollectionPage != null) {
                final List<DeviceCompliancePolicy> deviceCompliancePolicies = deviceCompliancePolicyCollectionPage
                        .getCurrentPage();
                allDeviceCompliancePolicies.addAll(deviceCompliancePolicies);
                final DeviceCompliancePolicyCollectionRequestBuilder nextPage = deviceCompliancePolicyCollectionPage
                        .getNextPage();
                if (nextPage == null) {
                    break;
                } else {
                    deviceCompliancePolicyCollectionPage = nextPage.buildRequest().get();
                }
            }

From the javadoc its clear the settings are seen in DeviceManagementSettings class, however im unable to get an instance of that class using graph api.

Any help to resolve the above is greatly appreciated!

1

1 Answers

0
votes

Below is the code snippet for fetch Compliance policy settings from Intune.

GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();

DeviceManagementSettings deviceManagementSettings = graphClient.customRequest("/deviceManagement/settings", DeviceManagementSettings.class)
    .buildRequest()
    .get();

The easiest way to find the code snippet for any Graph api is by using Graph Explorer, run the api and check Code snippets