API Usage - Enforce Mobile Device Name

ururk
New Contributor II

(This is for the classic API)

Is there a way to Enforce the Mobile Device Name when setting the display name via the API?

I tried:

jamf.put('/mobiledevices/id/IPAD_ID'...

<mobile_device>
  <general>
    <device_name_type>on</device_name_type>
    <device_name>TEST Device Name</device_name>
  </general>
  <location>
    <room>room</room>
 </location>
</mobile_device>

but it doesn't seem to work, and I cannot find any documentation

7 REPLIES 7

chriscollins
Valued Contributor

@ururk If you want to enforce the mobile name and have the "Enforce Mobile Device Name" checkbox checked you actually have to use the mobile device command api endpoint to do that. You'll send that command and then it will send a push to rename the device but also set it to keep it named that name.

/JSSResource/mobiledevicecommands/command/DeviceName/<what you want the name of the device to be>/id/<devices_id_number_in_jss>

Also I should add that if you ONLY run this command the name won’t be reflected in the inventory until the next inventory on that device completes (though if you click edit under general where it’s name is you will see that the desired name is set to be enforced)

ururk
New Contributor II

Thanks! Will try our soon.

ururk
New Contributor II

This worked! Thanks.

Stupid question... how did you know this? I could not find this listed anywhere in the documentation, but perhaps I wasn't looking closely enough?

chriscollins
Valued Contributor

@ururk To be completely honest I couldn't find it documented anywhere either but I had noticed when I manually clicked the box under the computers name to enforce naming, under the management section for the device I noticed it was sending a device rename push command, so I thought that "well lets check the /api playground if there is a documented device rename mobile command" and there was so I thought "ok, well maybe if I set the command through the API, maybe it will also check the box" and it did when I tested it. So that's about it. haha

One thing to keep in mind is that if there is already a device rename push command pending, any new ones will fail, so for one of my scripts that renames iOS devices based on membership in a smart group, I also run the /commandflush command on the device before I do the renaming command just to make sure there aren't any failures or conflicts.

kwsenger
Contributor

@ururk & @chriscollins Would you give me a hand if you have time to dig up the script you have used in the past to achieve this? It looks like you have overcome this issue. Looking to enforce a new Mobile Device Name and send out a push command via the API using Curl. I have modified a script we are currently using to update a device name manually
We get Syntax errors when using this.

Thanks for any advice on an older post.
Karl.

#!/bin/sh

#This script works ever time and trying to adjust it to change the device name and send a new push command

#Variables
jssAPIUsername="usernameHere"
jssAPIPassword="passwordHere"
jssAddress="https://myDistrictJSSHere:8443"
serialNumber="DeviceSerialNumber"
displayName="9708-TEST"

#Submit data to the API
    apiData="<mobile_device><general><display_name>$displayName</display_name><device_name>$displayName</device_name><name>$displayName</name></general></mobile_device>"
    output=`curl -sS -k -i -u ${jssAPIUsername}:${jssAPIPassword} -X PUT -H "Content-Type: text/xml" -d "<?xml version="1.0" encoding="ISO-8859-1"?>$apiData" ${jssAddress}/JSSResource/mobiledevices/serialnumber/$serialNumber`

exit 0

## -------------This is the new section I came up with
#Submit data to the API
apiData="<mobile_device><general><display_name>$displayName</display_name><device_name>$displayName</device_name><name>$displayName</name></general></mobile_device>"

#Modifications to Enforce new name
output=`curl -sS -k -i -u ${jssAPIUsername}:${jssAPIPassword} -X PUT -H "Content-Type: text/xml" -d "<?xml version="1.0" encoding="ISO-8859-1"?>$apiData" ${jssAddress}/JSSResource/mobiledevicecommands/command/DeviceName/<9708-TEST>/id/<5127>`

chriscollins
Valued Contributor

@kwsenger I only took a super quick look at that last line but you shouldn't have the name of the device and ID inside carrots like that.

output=`curl -sS -k -i -u ${jssAPIUsername}:${jssAPIPassword} -X PUT -H "Content-Type: text/xml" -d "<?xml version="1.0" encoding="ISO-8859-1"?>$apiData" ${jssAddress}/JSSResource/mobiledevicecommands/command/DeviceName/9708-TEST/id/5127`

cdenesha
Valued Contributor II

@kwsenger Yes an old reply, but maybe someone else will search for this in the future. :)

The API format for /mobiledevicecommands does not use a PUT but a POST. You do not have to update the <general><display_name> as the command will do it for you.

output=`curl -sS -k -i -u ${jssAPIUsername}:${jssAPIPassword} ${jssAddress}/JSSResource/mobiledevicecommands/command/DeviceName/${displayName}/id/${jssID} -X POST`

chris