RestAPI output was xml, now something else?

Sonic84
Contributor III

I wrote a simple script to pull the list of distribution points from the JSS using the rest api: https://yourjsscom:8443/apiFrontPage.rest. However after several successful runs Friday, today I'm met with an error. It looks like the structure of the File I'm downloading has changed from usual XML to this:

{"distribution_points":{"distribution_point":[{"id":82,"name":"dp1.company.com"},{"id":18,"name":"dp2.company.com"},{"id":29,"name":"dp3.company.com"}, ....

The code I was using in my script to get the list is:

curl -o $temp_file.xml -u $jss_login     https://casper.servername.com:8443/JSSResource/distributionpoints -X GET

Does anyone know why this would change all of a sudden? Or how I can specifically curl an xml favor of the list?

Thank you!

1 ACCEPTED SOLUTION

gregneagle
Valued Contributor

That's JSON output. There are lots of tools for working with JSON; both Python and Ruby have excellent JSON libraries, and of course JavaScript can handle it natively. If you are running Mountain Lion and would like to convert this to Plist XML-style, plutil can help: `plutil -convert xml1 -o /path/to/output.plist /path/to/input.json`

View solution in original post

4 REPLIES 4

gregneagle
Valued Contributor

That's JSON output. There are lots of tools for working with JSON; both Python and Ruby have excellent JSON libraries, and of course JavaScript can handle it natively. If you are running Mountain Lion and would like to convert this to Plist XML-style, plutil can help: `plutil -convert xml1 -o /path/to/output.plist /path/to/input.json`

Sonic84
Contributor III

Thanks for the code. that worked well to get it back into XML. Though I'm still wondering why I'd get xml from the JSS on Friday then JSON on Monday when "nothing" changed?

tlarkin
Honored Contributor

Hey Jeff,

I have seen this happen before, but only in certain environments. By default our API should always return results in XML. However, with certain combinations of software I have seen the default change to JSON. The only time I have seen this though, is with RHEL 6.3 and Java 7 (both Oracle and Open JDK). Something in the Java libraries changed in Java 7 on RHEL (vendor supplied package, RPM) where it actually flipped our default from XML to JSON instead.

I was not able to reproduce this with any of my Debian/Ubuntu/BSD virtual machines. I was able to reproduce it with CentOS and RHEL. So, I have not had the time to test ever single combination of Java/OS out there for a JSS install either.

The REST API can actually return the application type of your choice via the curl command. You can also PUT/POST in the same manner by specifying a content type. When you are grabbing the information you need with the API use the -H switch in your curl command to specify which application you wish to have the data returned in. This tells curl to use that specific header type.

So for example:

curl -sv -H "Accept: application/xml"  use:pass@https://myjss.com:8443/path/to/data -X GET

You will have to excuse my syntax if it is wrong I just wrote this really quick from memory. So, you can have your curl commands output in whatever format you want. If you want to change the default behavior of the REST API with your JSS, you may have to look at any Java updates that have been applied recently.

Thanks,
Tom

Sonic84
Contributor III

Hi Tom, The state of the server (JSS version, patch version, etc...) has not changed. Our JSS is on a Win2k8r2 cluster. We've got Java 1.7.0_17 installed still.

Thank you for the tip about curl, it works well:

curl -sv -H "Accept: application/xml" -u $user_name https://myJSS.com:8443/JSSResource/distributionpoints -X GET