API response is JSON instead XML

anverhousseini
Contributor II
Contributor II

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.

1 ACCEPTED SOLUTION

chriscollins
Valued Contributor

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.

View solution in original post

5 REPLIES 5

chriscollins
Valued Contributor

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.

anverhousseini
Contributor II
Contributor II

@chriscollins This was the solution, thank you! But shouldn't be XML by default?

talkingmoose
Honored Contributor II
Honored Contributor II

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.

mjhersh
New Contributor III

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.

mm2270
Legendary Contributor III
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.