microsoftgraph / msgraph-sdk-python

MIT License
360 stars 50 forks source link

Create managedDevice example not working #731

Open dotconfig404 opened 4 months ago

dotconfig404 commented 4 months ago

Describe the bug

In the SDK documentation for creating managed devices there is an example which does not work, I am not sure if this is a user error or a bug, maybe someone can help me here?

The example I am talking about is here, specifically the python version. https://learn.microsoft.com/en-us/graph/api/intune-devices-manageddevice-create?view=graph-rest-1.0&tabs=python

I am getting a 400 Bad Request error when using the example. The client object itself is not the problem, it works for all other calls without issues, my application has the required API permissions, but this is not related to that either since the error shows up without any permissions anyways.

Expected behavior

Should create a managed device when calling device_management.managed_devices.post(device)

How to reproduce

import asyncio
from azure.identity.aio import ClientSecretCredential
from msgraph import GraphServiceClient
from kiota_abstractions.api_error import APIError
from msgraph.generated.models.managed_device import ManagedDevice
from msgraph.generated.models.managed_device_owner_type import ManagedDeviceOwnerType
from msgraph.generated.models.device_action_result import DeviceActionResult
from msgraph.generated.models.action_state import ActionState
from msgraph.generated.models.compliance_state import ComplianceState
from msgraph.generated.models.management_agent_type import ManagementAgentType
from msgraph.generated.models.device_enrollment_type import DeviceEnrollmentType
from msgraph.generated.models.device_registration_state import DeviceRegistrationState
from msgraph.generated.models.device_management_exchange_access_state import DeviceManagementExchangeAccessState
from msgraph.generated.models.device_management_exchange_access_state_reason import DeviceManagementExchangeAccessStateReason
from msgraph.generated.models.configuration_manager_client_enabled_features import ConfigurationManagerClientEnabledFeatures
from msgraph.generated.models.device_health_attestation_state import DeviceHealthAttestationState
from msgraph.generated.models.managed_device_partner_reported_health_state import ManagedDevicePartnerReportedHealthState

TENANT_ID = 'tenant id'
CLIENT_ID =  'client id'
CLIENT_SECRET =  'client secret'

async def main():
    credentials = ClientSecretCredential(TENANT_ID, CLIENT_ID, CLIENT_SECRET)
    scopes = ['https://graph.microsoft.com/.default']
    client = GraphServiceClient(credentials=credentials, scopes=scopes)

    device = ManagedDevice(
        odata_type = "#microsoft.graph.managedDevice",
        user_id = "User Id value",
        device_name = "Device Name value",
        managed_device_owner_type = ManagedDeviceOwnerType.Company,
        device_action_results = [
            DeviceActionResult(
                odata_type = "microsoft.graph.deviceActionResult",
                action_name = "Action Name value",
                action_state = ActionState.Pending,
                start_date_time = "2016-12-31T23:58:46.7156189-08:00",
                last_updated_date_time = "2017-01-01T00:00:56.8321556-08:00",
            ),
        ],
        enrolled_date_time = "2016-12-31T23:59:43.797191-08:00",
        last_sync_date_time = "2017-01-01T00:02:49.3205976-08:00",
        operating_system = "Operating System value",
        compliance_state = ComplianceState.Compliant,
        jail_broken = "Jail Broken value",
        management_agent = ManagementAgentType.Mdm,
        os_version = "Os Version value",
        eas_activated = True,
        eas_device_id = "Eas Device Id value",
        eas_activation_date_time = "2016-12-31T23:59:43.4878784-08:00",
        azure_a_d_registered = True,
        device_enrollment_type = DeviceEnrollmentType.UserEnrollment,
        activation_lock_bypass_code = "Activation Lock Bypass Code value",
        email_address = "Email Address value",
        azure_a_d_device_id = "Azure ADDevice Id value",
        device_registration_state = DeviceRegistrationState.Registered,
        device_category_display_name = "Device Category Display Name value",
        is_supervised = True,
        exchange_last_successful_sync_date_time = "2017-01-01T00:00:45.8803083-08:00",
        exchange_access_state = DeviceManagementExchangeAccessState.Unknown,
        exchange_access_state_reason = DeviceManagementExchangeAccessStateReason.Unknown,
        remote_assistance_session_url = "https://example.com/remoteAssistanceSessionUrl/",
        remote_assistance_session_error_details = "Remote Assistance Session Error Details value",
        is_encrypted = True,
        user_principal_name = "User Principal Name value",
        model = "Model value",
        manufacturer = "Manufacturer value",
        imei = "Imei value",
        compliance_grace_period_expiration_date_time = "2016-12-31T23:56:44.951111-08:00",
        serial_number = "Serial Number value",
        phone_number = "Phone Number value",
        android_security_patch_level = "Android Security Patch Level value",
        user_display_name = "User Display Name value",
        configuration_manager_client_enabled_features = ConfigurationManagerClientEnabledFeatures(
            odata_type = "microsoft.graph.configurationManagerClientEnabledFeatures",
            inventory = True,
            modern_apps = True,
            resource_access = True,
            device_configuration = True,
            compliance_policy = True,
            windows_update_for_business = True,
        ),
        wi_fi_mac_address = "Wi Fi Mac Address value",
        device_health_attestation_state = DeviceHealthAttestationState(
            odata_type = "microsoft.graph.deviceHealthAttestationState",
            last_update_date_time = "Last Update Date Time value",
            content_namespace_url = "https://example.com/contentNamespaceUrl/",
            device_health_attestation_status = "Device Health Attestation Status value",
            content_version = "Content Version value",
            issued_date_time = "2016-12-31T23:58:22.1231038-08:00",
            attestation_identity_key = "Attestation Identity Key value",
            reset_count = 10,
            restart_count = 12,
            data_excution_policy = "Data Excution Policy value",
            bit_locker_status = "Bit Locker Status value",
            boot_manager_version = "Boot Manager Version value",
            code_integrity_check_version = "Code Integrity Check Version value",
            secure_boot = "Secure Boot value",
            boot_debugging = "Boot Debugging value",
            operating_system_kernel_debugging = "Operating System Kernel Debugging value",
            code_integrity = "Code Integrity value",
            test_signing = "Test Signing value",
            safe_mode = "Safe Mode value",
            windows_p_e = "Windows PE value",
            early_launch_anti_malware_driver_protection = "Early Launch Anti Malware Driver Protection value",
            virtual_secure_mode = "Virtual Secure Mode value",
            pcr_hash_algorithm = "Pcr Hash Algorithm value",
            boot_app_security_version = "Boot App Security Version value",
            boot_manager_security_version = "Boot Manager Security Version value",
            tpm_version = "Tpm Version value",
            pcr0 = "Pcr0 value",
            secure_boot_configuration_policy_finger_print = "Secure Boot Configuration Policy Finger Print value",
            code_integrity_policy = "Code Integrity Policy value",
            boot_revision_list_info = "Boot Revision List Info value",
            operating_system_rev_list_info = "Operating System Rev List Info value",
            health_status_mismatch_info = "Health Status Mismatch Info value",
            health_attestation_supported_status = "Health Attestation Supported Status value",
        ),
        subscriber_carrier = "Subscriber Carrier value",
        meid = "Meid value",
        total_storage_space_in_bytes = 8,
        free_storage_space_in_bytes = 7,
        managed_device_name = "Managed Device Name value",
        partner_reported_threat_state = ManagedDevicePartnerReportedHealthState.Activated,
        require_user_enrollment_approval = True,
        management_certificate_expiration_date = "2016-12-31T23:57:59.9789653-08:00",
        iccid = "Iccid value",
        udid = "Udid value",
        notes = "Notes value",
        ethernet_mac_address = "Ethernet Mac Address value",
        physical_memory_in_bytes = 5,
        enrollment_profile_name = "Enrollment Profile Name value",
    )

    result = await client.device_management.managed_devices.post(device)

if __name__ == "__main__":
    asyncio.run(main())
msgraph.generated.models.o_data_errors.o_data_error.ODataError: 
        APIError
        Code: 400
        message: None
        error: MainError(additional_data={}, code='No method match route template', details=None, inner_error=InnerError(additional_data={}, client_request_id='8e3ad6b2-4b54-49cf-bd46-1192c7f7b6a9', date=DateTime(2024, 5, 29, 11, 54, 43, tzinfo=Timezone('UTC')), odata_type=None, request_id='36aa37e2-67a9-4e30-9c57-bd46666afa6e'), message='No OData route exists that match template ~/singleton/navigation with http verb POST for request /DeviceFE/StatelessDeviceFEService/deviceManagement/managedDevices.', target=None)

SDK Version

No response

Latest version known to work for scenario above?

No response

Known Workarounds

No response

Debug output

Click to expand log ``` ```

Configuration

No response

Other information

No response

shemogumbe commented 4 months ago

Thanks @dotconfig404 for using the SDK and for raising this.

This needs to be investigated to see if the SDK is generated for a functionality that does not exist in the Graph SDK.

We could try run the http version to confirm this, otherwise the our team will look into this.

dotconfig404 commented 3 months ago

I have tried using the Graph Explorer to check the http version, but it gave the same error back:

{
    "error": {
        "code": "No method match route template",
        "message": "No OData route exists that match template ~/singleton/navigation with http verb POST for request /DeviceFE/StatelessDeviceFEService/deviceManagement/managedDevices.",
        "innerError": {
            "date": "2024-06-04T13:40:19",
            "request-id": "b0426bf9-566e-4af6-9cdf-55da30716958",
            "client-request-id": "bda47207-c55f-6a51-97a0-2d5ca2c0dcf9"
        }
    }
}