You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When attempting to create a smart group, the API is returning Error: Name, and/or, search_type are required in criterion. According to the SDK models in the docs, the data I'm giving it is valid, but the XML conversion seems to be broken. See below.
Steps to Reproduce
from jamf_pro_sdk import JamfProClient, SessionConfig
from jamf_pro_sdk.models.classic import computer_groups
from jamf_pro_sdk.clients.auth import ApiClientCredentialsProvider
jamfClient = JamfProClient(
server=jamfURL,
credentials=ApiClientCredentialsProvider(jamfClientID, jamfClientSecret),
session_config=SessionConfig(**{"timeout": 30, "max_retries": 3})
)
## example var to populate actual code
productVersion = 15
## get existing group data
updatedDevicesGroupData = jamfClient.classic_api_request("get", "computergroups/name/[jamf sdk test] macOS Version Current")
## get group ID etc if exists
if updatedDevicesGroupData.ok:
groupID = updatedDevicesGroupData.json().get("computer_group").get("id")
groupData = jamfClient.classic_api.get_computer_group_by_id(groupID)
## set new criterion value and update group
groupData.criteria[0].value = productVersion
jamfClient.classic_api.update_smart_computer_group_by_id(groupID, groupData)
## if the group doesn't exist, create it
else:
groupCriteria = computer_groups.ClassicCriterion(
name="Operating System Version",
priority=0,
and_or="and",
search_type="greater than or equal",
opening_paren=False,
closing_paren=False,
value=productVersion
)
newgroupData = computer_groups.ClassicComputerGroup(
name="[jamf sdk test] macOS Version Current",
is_smart=True,
criteria=[groupCriteria]
)
jamfClient.classic_api.create_computer_group(newgroupData)
Expected Result
The smart computer group should either be updated or created with the correct criteria.
Actual Result
The same result is observed with both create and update operation attempts. The SDK appears to validate the input, but the XML generated and sent to jamf is incorrect. Specifically, the and_or and search_type values are being split into single-character None items, when they should be simple strings. The API response also references a missing Name criterion attribute, but I'm not sure what's causing that, as that key seems to be generated properly.
## get existing group dataupdatedDevicesGroupData=jamfClient.classic_api_request("get", "computergroups/name/[jamf sdk test] macOS Version Current")
## get group ID etc if existsifupdatedDevicesGroupData.ok:
groupID=updatedDevicesGroupData.json().get("computer_group").get("id")
groupData=jamfClient.classic_api.get_computer_group_by_id(groupID)
## set new criterion value and update groupgroupData.criteria[0].value=productVersionjamfClient.classic_api.update_smart_computer_group_by_id(groupID, groupData)
You're making two calls for the same object. You can init a model from the response of the first computergroups/name request:
updatedDevicesGroupData=jamfClient.classic_api_request("get", "computergroups/name/[jamf sdk test] macOS Version Current")
computer_groups.ClassicComputerGroup(**updatedDevicesGroupData.json()["computer_group"])
Ahh excellent, I hadn't considered I could just re-use the data I already fetched.
Anyway, I've tested with the branch containing the fix for this, and can confirm it now works as expected! There was one warning (which is easily worked around by typecasting the value as a string):
/Users/$me/Library/Python/3.12/lib/python/site-packages/pydantic/main.py:364: UserWarning: Pydantic serializer warnings:
Expected `str` but got `int` - serialized value may not be as expected
return self.__pydantic_serializer__.to_python(
Array item: {'name': 'Operating System Version', 'priority': 0, 'and_or': 'and', 'search_type': 'greater than or equal', 'value': 15, 'opening_paren': False, 'closing_paren': False}```
When attempting to create a smart group, the API is returning
Error: Name, and/or, search_type are required in criterion.
According to the SDK models in the docs, the data I'm giving it is valid, but the XML conversion seems to be broken. See below.Steps to Reproduce
Expected Result
The smart computer group should either be updated or created with the correct criteria.
Actual Result
The same result is observed with both create and update operation attempts. The SDK appears to validate the input, but the XML generated and sent to jamf is incorrect. Specifically, the
and_or
andsearch_type
values are being split into single-characterNone
items, when they should be simple strings. The API response also references a missingName
criterion attribute, but I'm not sure what's causing that, as that key seems to be generated properly.SDK generated XML:
System Information
macOS 14.5
Python 3.12.1
Jamf Pro 11.7.0
Jamf Python SDK 0.6a1
The text was updated successfully, but these errors were encountered: