API JSON output possibly missing keys

luke_reagor
Contributor II

I'm having trouble with the API and making changes with JSON.

First, it's confusing because when looking at https://jamf.domain.com:8443/API and testing /mobiledeviceapplications, the output JSON looks to be missing keys when compared to the XML version.

In this pic, you can see that the XML returns a <mobile_device_group> element for each group inside the <mobile_device_groups> element. In the JSON version, the mobile_device_group key is missing and the groups are directly underneath the mobile_device_groups key.
f3bdbf4af49c4c8d9406e43ca57b1fd7

Second, when it comes to sending data to /mobiledeviceapplications, I can get XML to work, but not JSON. In my JSON tests, I've tried with the mobile_device_group key added and removed, but neither work.

Here's the tests I'm using:

jssuser="jssuser"
jsspass="jsspass"
jssserver="https://jamf.domain.com:8443"


#WORKING XML
curl -k -s -u $jssuser:$jsspass -X PUT -H "Content-Type: application/xml" -H "Accept: application/xml" -d '<?xml version="1.0" encoding="UTF-8" ?><mobile_device_application><scope><mobile_device_groups><mobile_device_group><id>883</id></mobile_device_group><mobile_device_group><id>128</id></mobile_device_group></mobile_device_groups></scope></mobile_device_application>' $jssserver/JSSResource/mobiledeviceapplications/id/171


#NON-WORKING JSON WITH mobile_device_group
curl -k -s -u $jssuser:$jsspass -X PUT -H "Content-Type: application/json" -H "Accept: application/json" -d '{"mobile_device_application": {"scope": {"mobile_device_groups": {"mobile_device_group": [{"id": "883","name": "+test+"},{"id": "128","name": "+tech+"}]}}}}' $jssserver/JSSResource/mobiledeviceapplications/id/171


#NON-WORKING JSON WITHOUT mobile_device_group
curl -k -s -u $jssuser:$jsspass -X PUT -H "Content-Type: application/json" -H "Accept: application/json" -d '{"mobile_device_application": {"scope": {"mobile_device_groups": [{"id": "883","name": "+test+"},{"id": "128","name": "+tech+"}]}}}' $jssserver/JSSResource/mobiledeviceapplications/id/171

Can anyone shed some light on the issue? Are we not able to do API PUTs with JSON or is there a bug in the API?

4 REPLIES 4

Asnyder
Contributor III

You can get JSON from the API but it will not accept it.

cdenesha
Valued Contributor II

What @Asnyder said.

To use JSON for sending to the API you need to use the new Jamf Pro API that is not quite complete (they are still building it out), which doesn't use XML. https://jamf.domain.com:8443/uapi/doc/

luke_reagor
Contributor II

Thanks for the info, guys! That’s what I needed to know!

luke_reagor
Contributor II

I guess there one more thing still...
In the first part of my issue I mentioned that the JSON output is not showing the mobile_device_group key. Is this a bug? Because converting the json to xml will not include the missing key and therefor fail when used by the api.