Posted on 04-01-2018 02:26 PM
Hi
I wrote a script which makes a GET request. Like this:
curl -H "content-type: application/xml" -s -o "/private/tmp/computers.xml" -fku "username":"password" "https://jamf.example.com/JSSResource/computers" -X GET
If the inventory contains 0 computers I get a JSON response. If there are more than 0 computers the output is XML, which is correct. This happens only on Jamf Pro 10.3.
Is this a product issue or is my curl command wrong? I even tried to force a XML response by defining the header.
Solved! Go to Solution.
Posted on 04-01-2018 03:47 PM
You are using the wrong header to specify you want XML. You use “Content-type:” when telling the server what to expect from you when you are sending to the server. You should use “Accept:” to tell the server what you expect to receive back when asking for information.
Posted on 04-01-2018 03:47 PM
You are using the wrong header to specify you want XML. You use “Content-type:” when telling the server what to expect from you when you are sending to the server. You should use “Accept:” to tell the server what you expect to receive back when asking for information.
Posted on 04-02-2018 12:02 AM
@chriscollins This was the solution, thank you! But shouldn't be XML by default?
Posted on 04-02-2018 05:53 AM
My understanding is that XML use to be the default, but a change in Java a couple years ago caused the default to change to JSON. Regardless, good form is to specify the content type in your curl command that you'll accept.
Posted on 04-02-2018 05:59 AM
I remember a few versions ago (I think 9.96 or 9.98) the default for many things changed from xml to json and I had to update my scripts to explicitly request xml. And yet now, on 9.101, I just ran some tests and can't find anything that defaults to json. Hmm. Maybe it was just a bug.
In any case, it seems prudent to explicitly request the data type as a matter of habit.
Posted on 04-02-2018 07:18 AM
In any case, it seems prudent to explicitly request the data type as a matter of habit.
This is exactly what I do now with all API scripts, even if I'm almost 100% certain the default response will be XML. I explicitly specify it anyway, just to be doubly sure.