
UNSOLVED
WMS API - Search for Workstation by name
Has anyone figured out how to do an API search for a workstation by its name? The only thing I have figured out is to iterate thru all the deviceID pages and search for the name. Which is really inefficient.
My PHP / CURL Code - (trying to figure out how to get this to PowerShell as well)
$workstation = $_GET['workstation'];
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https:// /wms-api/wms/v1/SessionService/Sessions',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_HEADER => true,
CURLOPT_ENCODING => '',
CURLOPT_TIMEOUT => 0,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{"UserName":"User","Password":"Password"}',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json'
),
));
$authresponse = curl_exec($curl);
// Process response and pull token to variable
$header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$header = substr($authresponse, 0, $header_size);
$headers = explode('X-Auth-Token:', $header, 2);
$token = explode('Cache-Control:', $headers[1], 2);
$machinefound = "false";
$deviceinfo = "";
for($page = 1; $page <= 1000 ;$page++){
// Find device id by pulling device list
curl_setopt_array($curl, array(
CURLOPT_URL => 'https:// /wms-api/wms/v1/Systems?page=' . $page,
CURLOPT_HEADER => false,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'X-Auth-Token: ' . $token[0]
),
));
$sysresponse = curl_exec($curl);
// Process response and pull the $device
$devices = json_decode($sysresponse,true);
array_filter($devices["Members"], function ($var) use ($workstation) {
foreach($var as $device){
if (stripos($var['Oem']['SystemName'],$workstation) !== false){
global $deviceinfo;
$deviceinfo = $var['@odata.id'];
$page = 10001;
return true;
} else {
return false;
}
};
});
if($deviceinfo != ""){
break;
}
}
// Get the device information
curl_setopt_array($curl, array(
CURLOPT_URL => 'https:// /wms-api' . $deviceinfo,
CURLOPT_HEADER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'X-Auth-Token: ' . $token[0]
),
));
$deviceresponse = curl_exec($curl);
// Process device info and return the json results
$header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$header = substr($deviceresponse, 0, $header_size);
$device = json_decode(substr($deviceresponse, $header_size),true);
Responses (0)
Solutions (0)
