Skip to main content
Solved

API response is JSON instead XML


Forum|alt.badge.img+11

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.

Best answer by chriscollins

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 original
Did this topic help you find an answer to your question?

5 replies

Forum|alt.badge.img+16
  • Honored Contributor
  • 403 replies
  • Answer
  • April 1, 2018

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.


Forum|alt.badge.img+11
  • Author
  • Valued Contributor
  • 98 replies
  • April 2, 2018

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


talkingmoose
Forum|alt.badge.img+36
  • Legendary Contributor
  • 1900 replies
  • April 2, 2018

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.


Forum|alt.badge.img+12
  • Contributor
  • 37 replies
  • April 2, 2018

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.


Forum|alt.badge.img+16
  • Legendary Contributor
  • 7880 replies
  • April 2, 2018
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.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings