macadmins / jamf-pro-sdk-python

A client library for the Jamf Pro APIs and webhooks.
https://macadmins.github.io/jamf-pro-sdk-python/
MIT License
48 stars 10 forks source link

[Bug] send_mdm_command_preview broken? #16

Closed jausmus-wayspring closed 12 months ago

jausmus-wayspring commented 12 months ago

When I run the send_mdm_command_preview with a UUID and a command, I get a pydantic.error_wrappers.ValidationError

Steps to Reproduce

from jamf_pro_sdk import JamfProClient
from jamf_pro_sdk.clients import auth
from jamf_pro_sdk.models.pro.mdm import LogOutUserCommand

client = JamfProClient(
    server="*.jamfcloud.com",
    credentials=auth.ApiClientCredentialsProvider(
        client_id="",
        client_secret=""
    )
)

logout_user = client.pro_api.send_mdm_command_preview(
    management_ids=[""],
    command=LogOutUserCommand
)

All empty quotes have valid values.

Expected Result

The MDM command is sent successfully.

Actual Result

Traceback (most recent call last):
  File "/Users/jasonausmus/repos/wayspring-jamf/auth.py", line 14, in <module>
    logout_user = client.pro_api.send_mdm_command_preview(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jasonausmus/.local/share/virtualenvs/wayspring-jamf-_868w2GM/lib/python3.11/site-packages/jamf_pro_sdk/clients/pro_api/__init__.py", line 232, in send_mdm_command_preview
    data = SendMdmCommand(
           ^^^^^^^^^^^^^^^
  File "pydantic/main.py", line 341, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 2 validation errors for SendMdmCommand
commandData
  Discriminator 'commandType' is missing in value (type=value_error.discriminated_union.missing_discriminator; discriminator_key=commandType)
commandData
  value is not a valid dict (type=type_error.dict)

I'm not sure what I'm doing wrong here and I can't find any documented examples of using this method.

System Information

brysontyrrell commented 12 months ago

@jausmus-wayspring You need to instantiate the command object you're passing. Can you try:

logout_user = client.pro_api.send_mdm_command_preview(
    management_ids=["<ID>"],
    command=LogOutUserCommand()
)

Few things I will start on related to this issue:

jausmus-wayspring commented 12 months ago

Thanks @brysontyrrell, instantiating it resolved the issue.