C# Graph SDK - How to deploy an Intune device compliance policy

244 Views Asked by At

I am trying to deploy an Intune device compliance policy in my C# program. I have successfully been able to deploy a configuration profile, but a compliance policy is proving to be a tough nut to crack

Authentication to Graph is done with the graph service client, and I have gotten that to work. Permissions are also OK. Currently the app is working on my developer azure tenant.

My code is as follows:

var policyID = "ID TO MY POLICY";
var groupID = "ID TO MY GROUP";

var groupAssignmentTarget = new GroupAssignmentTarget 
 {  GroupId = groupID };    


   
var policyAssignment = new DeviceCompliancePolicyAssignment
 { Target = groupAssignmentTarget };           

await client.DeviceManagement.DeviceCompliancePolicies[policyID]
.Assignments
.Request()
.AddAsync(policyAssignment );

The error I am getting is

Microsoft.Graph.ServiceException: 'Code: No method match route template

Message: No OData route exists that match template ~/singleton/navigation/key/navigation with http verb POST for request /DeviceConfiguration_2306/StatelessDeviceConfigurationFEService/deviceManagement/deviceCompliancePolicies

I have verified that the groupID and policyID is valid. According to the documentation as well as github copilot x this should work. The same format is used for configuration profiles, and that does work.

1

There are 1 best solutions below

0
D Randall On

Aside from updating the SDK to fix the problem, if others run into this (or similar issues), the easiest way to ensure you have your path set correctly is to use F12 dev tools or fiddler and trace the call from the Intune console UI that mimics the workflow you want. Sometimes there are multiple ways to perform the same operation, and the error you're getting is saying that way you've formed your graph call doesn't have any code to respond to that format.