Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect JSON payload formatting for ScheduledActionsForRule.PostAsync(), and wrong URL for POST call #758

Closed
billgatesfan opened this issue Nov 14, 2023 · 3 comments
Labels
Needs: Attention 👋 Question: SDK Not actionable. Question related to the SDK.

Comments

@billgatesfan
Copy link

billgatesfan commented Nov 14, 2023

I would like to report 2 possible bugs :

First problem is :

When calling graphServiceClient.DeviceManagement.DeviceCompliancePolicies[Id].ScheduledActionsForRule.PostAsync(deviceComplianceScheduledActionsForRule)

the object deviceComplianceScheduledActionsForRule is serialized to sth like :

    {
        "ruleName": "PasswordRequired",
        "scheduledActionConfigurations": [
            {
                "actionType": "block",
                "gracePeriodHours": 24,
                "notificationMessageCCList": [],
                "notificationTemplateId": "00000000-0000-0000-0000-000000000000"
            }
        ]
    }

...as it sticks to this object definition :

Unfortunately, this makes the call to always fail. If you replay the above JSON payload manually with MS GraphExplorer website, you get an error.

When debugging the same action in Intune Portal, the browser sends this JSON payload :

    {
        "deviceComplianceScheduledActionForRules": [
            {
                "ruleName": "PasswordRequired",
                "scheduledActionConfigurations": [
                    {
                        "actionType": "block",
                        "gracePeriodHours": 24,
                        "notificationTemplateId": "00000000-0000-0000-0000-000000000000",
                        "notificationMessageCCList": []
                    }
                ]
            }
        ]
    }

I expected the ScheduledActionsForRule.PostAsync() method, to serialize my deviceComplianceScheduledActionsForRule object, into a JSON property called deviceComplianceScheduledActionForRules, like done inside my browser.

The REST API documentation (https://learn.microsoft.com/en-us/graph/api/intune-deviceconfig-devicecompliancescheduledactionforrule-create?view=graph-rest-1.0&tabs=http) is not very clear, and the request example omits totally the "scheduledActionConfigurations" block.

The 2nd problem is :

In order to repro this scenario using Intune Portal with the POST call, you just need to edit an existing Compliance Policy, and change any setting in the "Actions for noncompliance" (change for example the value for "Mark device noncompliant" and save your profile). This will trigger a POST call to /beta/deviceManagement/deviceCompliancePolicies/[someID]/scheduleActionsForRules.
POST URL

Please notice the missing "d" after "schedule" and also the added "s" after "Rule", compared to the SDK or API documentation. This means, no matter what payload you pass to Graph Explorer, if you are using the auto-suggestion "scheduledActionsForRule" in the URL bar or this Graph SDK, it will always make your call to fail...

Expected behavior : harmonize the SDK with the real behavior of GraphAPI.

@andrueastman
Copy link
Member

Thanks for raising this @billgatesfan

I believe there are two endpoints here. But the correct one to look at would be the one documented at https://learn.microsoft.com/en-us/graph/api/intune-deviceconfig-devicecompliancepolicy-scheduleactionsforrules?view=graph-rest-1.0&tabs=http

Using the SDK you should be able to make the call as

var requestBody = new Microsoft.Graph.Beta.DeviceManagement.DeviceCompliancePolicies.Item.ScheduleActionsForRules.ScheduleActionsForRulesPostRequestBody
{
	DeviceComplianceScheduledActionForRules = new List<DeviceComplianceScheduledActionForRule>
	{
		new DeviceComplianceScheduledActionForRule
		{
			OdataType = "#microsoft.graph.deviceComplianceScheduledActionForRule",
			Id = "f0075d5e-5d5e-f007-5e5d-07f05e5d07f0",
			RuleName = "Rule Name value",
		},
	},
};
await graphClient.DeviceManagement.DeviceCompliancePolicies["{deviceCompliancePolicy-id}"].ScheduleActionsForRules.PostAsync(requestBody);

microsoftgraph/microsoft-graph-docs-contrib#8818 should fix the snippet generation for the relevan doc page.

@andrueastman andrueastman added Question: SDK Not actionable. Question related to the SDK. Needs: Author Feedback labels Nov 15, 2023
@billgatesfan
Copy link
Author

Oooooh my bad again 🫢. I was fooled by GraphExplorer (believing the "/microsoft.graph.scheduleActionsForRules" is sth broken), and by VS autocomplete :

scheduleActionsForRules_GraphExplorer_and_VS_autocomplete

Many traps in this API 😔. Thx so much again for the quick help and example.

Copy link
Contributor

No description provided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Attention 👋 Question: SDK Not actionable. Question related to the SDK.
Projects
None yet
Development

No branches or pull requests

2 participants