Skip to main content
Solved

Access to API doesn't work like expected

  • June 22, 2017
  • 2 replies
  • 24 views

mkolb
Forum|alt.badge.img+8

Hello!

Maybe someone has any idea? I try to get numbers from the JSS by using the API. I try to run this command:

var=$(curl -L -skfu jssuser:jsspassword ‘https://JSS_URL/JSSResource/computergroups/id/1' | /usr/bin/awk -F ‘<size>|</size>’ ‘{print $4}‘)

When I run this command with the URL of my test-jss it works like expected. But when I run it with the URL of my productive JSS it gets no value at all. I have no idea why.. the user and password are correct, if I try them on https://JSS_URL/api at “computergroups” it works, so should be no problem… any idea? Would be glad about any help…

Best answer by mm2270

Not 100% sure, but my guess is your production JSS is sending back JSON instead of xml. You may need to add a header to the curl command to tell it to send back xml, which is what the script expects.

curl -H "Accept: text/xml" -sfku jssuser:jsspassword ..... (rest of command)

As an aside, I've never needed to use the -L flag with curl against the API. That tells curl to follow links that it encounters which doesn't apply with the API as far as I know.

2 replies

mm2270
Forum|alt.badge.img+24
  • Legendary Contributor
  • Answer
  • June 22, 2017

Not 100% sure, but my guess is your production JSS is sending back JSON instead of xml. You may need to add a header to the curl command to tell it to send back xml, which is what the script expects.

curl -H "Accept: text/xml" -sfku jssuser:jsspassword ..... (rest of command)

As an aside, I've never needed to use the -L flag with curl against the API. That tells curl to follow links that it encounters which doesn't apply with the API as far as I know.


mkolb
Forum|alt.badge.img+8
  • Author
  • Contributor
  • June 23, 2017

Thank you mm2270!!! You really made my day :-)

Now it works!