Pulling Group XML from JPS via API - Getting Error

Hugonaut
Valued Contributor

I am trying to export groups XML sheets from the JPS via API.

When running the following script, i get an error, what is wrong? The Api Account has full access so its not a permission issue.

#!/bin/bash

curl -ksu APIuser:APIpass -H "accept:xml" https://jamfserver.com:8443/JSSResource/mobiledevicegroups/id/99 | xmllint -format - > ~/Desktop/test.xml

Produces the following Error

-:1: parser error : Start tag expected, '<' not found
{"mobile_device_group":{"id":99,"name":"Test Group","is_smart":false,"criteria
^

Can't for the life of me figure this out

I think i'm missing a flag after the format - (hyphen) then what>

xmllint -format -**HERE** >
________________
Looking for a Jamf Managed Service Provider? Look no further than Rocketman
1 ACCEPTED SOLUTION

ryan_ball
Valued Contributor

It looks like the result you are getting is JSON, not XML, and xmllint does not know what do do with it.

Try this:

-H "Accept: application/xml"

Instead of this:

-H "accept:xml"

View solution in original post

6 REPLIES 6

ryan_ball
Valued Contributor

@Hugonaut Does this work for you?

#!/bin/bash

APIuser=""
APIpass=""

curl -X GET -ksu "$APIuser:$APIpass" "https://jamfserver.com:8443/JSSResource/mobiledevicegroups/id/99" | xmllint --format - > ~/Documents/test.xml

exit 0

Also, I replied to your post about removing a device from all static groups:
https://www.jamf.com/jamf-nation/discussions/30498/how-to-remove-a-mobile-device-from-all-groups-wit...

Hugonaut
Valued Contributor

to the rescue again, thanks for following up to the other post I missed that, that's the other half of this posts end goal. Thanks for that gonna check it out.

as for this script, it's still exporting a blank sheet when viewing in any program, 0 characters, before, when i remove the hyphen after format i get a list of flags in the XML sheet instead of it actually pulling the data, heres a screenshot of the possible flags, working through them now - https://imgur.com/a/xEh5MEl

________________
Looking for a Jamf Managed Service Provider? Look no further than Rocketman

ryan_ball
Valued Contributor

It looks like the result you are getting is JSON, not XML, and xmllint does not know what do do with it.

Try this:

-H "Accept: application/xml"

Instead of this:

-H "accept:xml"

View solution in original post

Hugonaut
Valued Contributor

WOW.

great job man, worked like a charm. thank you for your help!

________________
Looking for a Jamf Managed Service Provider? Look no further than Rocketman

AdminIA
New Contributor III

Gah, I'm running into a similar issue, but the "Solved" post doesn't quite do it. I have an API call script that gets the assigned user's username (email address) and writes it to a file, as part of a Crashplan configuration process. It's been working great for a couple of months now, but just today it started failing with...

Script result: -:1: parser error : Start tag expected, '<' not found
{"computer":{"general":{"id":132,"name":"(theName of the Mac)","mac_address":"
^

The call in the script is...

id=$(curl -ksu "$username":"$password" -H "Accept: text/xml" "$server"/JSSResource/computers/serialnumber/"$sn" | xmllint --xpath "computer/general/id/text()" -)
email=$(curl -ksu $username:$password -H "content-type: text/xml" $server/JSSResource/computers/id/$id | xmllint --xpath '/computer/location/email_address/text()' - )

... then it (used to) writes the file. Now it errors. Any ideas?

SamF
Contributor

@AdminIA It looks like the issue is likely the same as above. In the portion of your code that assigns a value to the email variable, you're using the wrong header.
Try replacing:

-H "content-type: text/xml"

With:

-H "Accept: text/xml"

The "Accept" header is for telling the server what format you will accept the response in, typically used for GET operations. The "Content-Type" header is used to tell the server what format the content you're sending it is, typically used for PUT, POST and PATCH operations.