What is the proper syntax for PUT XML to update a Building

bvondeylen
Contributor II

I have tried this in Mac Terminal

curl -s -k -u $user:$pw -X PUT -H "Content-Type: text/xml" -d "<?xml version="1.0"?>" <mobile_device><location><building>AD</building></location></mobile_device> https://$myserver/JSSResource/mobiledevices/id/1957

I get this error message
-bash: syntax error near unexpected token `<'

I actually have my real username and password in place of the $user and $pw and my real server in place of the $myserver

Just wondering what the curl command should be since the one above isn't working.

3 REPLIES 3

talkingmoose
Moderator
Moderator

A couple of things:

  1. You don't need to include the XML version information in your code. You'll also want to wrap this in quotes in case your building name includes spaces. Use:
    "<mobile_device><location><building>AD</building></location></mobile_device>"

  2. Your building must already exist under Settings > Network Organization > Buildings.

Altogether, this is what worked for me:

curl -s -k -u $user:$pw -X PUT -H "Content-Type: text/xml" 
-d "<mobile_device><location><building>AD</building></location></mobile_device>" 
https://$myserver/JSSResource/mobiledevices/id/1957

bvondeylen
Contributor II

I finally got it working by using the following:

curl -s -k -u $user:$pw -X PUT -H "Accept: application/xml" -H "Content-Type: application/xml" -d "<mobile_device><general><display_name>$name</display_name></general><location><username>$username</username><department>$department</department><building>$building</building><room>$room</room></location></mobile_device>" https://$myserver/JSSResource/mobiledevices/id/$id

I don't know why I needed the -d in front of the XML, but it worked. I am not sure why this order of things worked either, or if the order can be different (example putting -X PUT right before the server instead of first thing at the beginning).

Either way, it worked, and I have not successfully PUT both Mobile Device Application information and Mobile Device information using FileMaker Pro.

mm2270
Legendary Contributor III

Just an FYI, you should not need the -H "Accept: application/xml" nor -H "Content-Type: application/xml" in there in my experience since right now the API can only accept XML for PUT and POST commands. So it's not expecting to be told what you're uploading. The header calls are only relevant for GET commands since it will default to JSON unless you tell it the format you want.

As for the -d, you needed that in there because it was inline data, not a file. If you piped the xml into a local file, you would instead use something like -T /path/to/file.xml

Finally, I'm pretty sure you can indeed change the order, so -X PUT can be at the end and it should still work fine, but don't quote me on that. Best to test it out and see.