Sensor API, the Undocumented adventure.

So at the time of writing the Workspace ONE API doco that comes with each instance has no doco around Sensors, and how to query them and what not.

You can reverse engineer it yourself, from the import_sensor_sample.ps1 script from Vmware Code, or I can share what I’ve done so far, which isnt much… but it’s a start.

First you need to know how to Auth to the API, see my article here

First up, construct our header. Different API’s require different Contet-Types, otherwise they can throw an error, for our purposes:

$header = @{
"Authorization" = "Basic $creds";
"aw-tenant-code" = $apikey;
"Accept" = "application/json";
"Content-Type"="application/json;version=2;"}

We need to get the OG UUID for the OG we are querying for sensors, to do this first we get the Group ID for the OG, so we can query for more info:

The Group ID is the Group ID given to your OG, you can find that in UEM.

$url="https://{yourserver}.awmdm.com/api/system/groups/search?groupID={yourOGName}"
$data=Invoke-RestMethod -Method Get -Uri $url -Headers $header
$OGGroupID=$data.LocationGroups.id.value

Now for the UUID, which required the OG Group ID

$url="https://{yourserver}awmdm.com/api/system/groups/$OGgroupID"
$data=Invoke-RestMethod -Method Get -Uri $url -Headers $header
$OGUUID=$data.Uuid

Now we can start doing some API stuffs…

Get a list of Sensors

This will return all the sensors:

$url="https://{yourserver}.awmdm.com/api/mdm/devicesensors/list/$OGUUID"
$data=Invoke-RestMethod -Method Get -Uri $url -Headers $header

Backup all the sensor code

One thing to note is that the output of the code is encoded, hence the conversion back at the end

$url="https://{yourserver}.awmdm.com/api/mdm/devicesensors/list/$OGUUID"
$data=Invoke-RestMethod -Method Get -Uri $url -Headers $header
foreach ($sensor in $data.result_set)
   {
   $url="https://as1356.awmdm.com/api/mdm/devicesensors/{0}" -f $uuid
   $sensordata=Invoke-RestMethod -Method Get -Uri $url -Headers $header     
   $f="{0}.ps1" -f $sensor.name
   [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($sensordata.script_data)) | Out-File .\$f
    }


Simple, and effective way of getting the Sensor Code out to back it up.

Closing

You can, of course, run $data in powershell, or whatever you call the variable, to see what the properties of each one returns to see what other data yuou can pull out.

The import_sensor_sample.ps1 also has examples of how to add sensors to the console, delete etc..

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.