How to write to a custom field using the FileWave API
FrequentlyIt youis mightoften find it convenientdesirable to publish data back to aalter FileWave Custom Field,Field values, especially when it comes to driving automated workflows.
API Therecalls arehave somethe distinct advantagesadvantage toof this...especiallychanging inCustom thatField thevalues data change is made server-side immediatelydirectly on the APIserver, call.essentially making the change immediate.
In this article, we'll show you how to do this with a macOS shell script and with a Windows PowerShell script for boolean, string and date/timeWhere Custom Field values.values are Note:driving We'llSmart readGroup datadevice frominclusion, despite the API ascall making an immediate change, there will still be a smartperiod startingof block.time Being smart is always good.
We recommend only attempting to amend Custom Fields that will not be updated otherwise through other methods, Inventory for example. 'Administrator' Data Types arebefore the mostnext obviousSmart choice.
The things we'll need to know to write a script:
FileWave server addressBase64 Encoded API token (from Assistants → Manage Administrators, and highly recommend a new admin account for this that has no rights assigned)The Internal Name of the field you want to updateThe type of Custom Field (string, boolean, integer, date/time)The Device ID of the device you want to test with (in an actual script, FileWave can supply this automatically through a launch argument)The URLs currently shown in this article useRESTful API (v1 API)so you will see 20445 used as a port. Simply add/api/to the front of the/inv/api/URL to make it. begin/api/inv/api/and you can use 443 instead like the other APIs use.
How to be Smart:
We can be smart by asking the API to show us data for Custom Fields we want to update. So, we'll look at details for a specific device that has values set. (Note this is a desktop client so we used /DesktopClient, but if a mobile device then it would be /MobileClient instead). Elements in blue would need to be replaced with values for your environment.
Howto | ||
Values
be
|
As you can see, the results above are the sameobserved from the API regardless of calling platform and the data forwithin the Custom Field definition.
It is also possible to use Swagger (or therefore another API call) to return the 'choices' list of any Custom Field, by observing the Custom Field definition:
URL path for query:
/api/inv/api/v1/custom_field/
Query response:
{
"to_be_deleted": false,
"field_name": "apple_battery_replace_2015",
"display_name": "macOS Apple Battery Replace 2015",
"data_type": "string",
"provider": 0,
"metadata": {},
"description": "",
"default_value": "Unchecked",
"choices": [
"Replaced",
"Recall",
"NA",
"Serial",
"Error",
"Unchecked"
],
"is_global": false,
"used_in_inventory_queries": false,
"used_in_smart_groups": false,
"used_in_filesets": false,
"used_in_license_definitions": false,
"used_in_dep_profiles": false,
"used_in_dep_rules": false,
"used_in_workflows": false
},
Which API
Custom Fields, as mentioned in the formother API KB documents, are best targeted with the Command Line RESTful API.
This example is demonstrating the possibility of antargeting array, so when we go to change it, we'll write it back that way as welldevices using theboth PATCHSerial commandNumber and anDevice arrayID. data structure.
Changing Values:
The basicServer's methodFQDN, forAPI changingauthentication a value looks like this, where you would again substitute your valuestoken and environmentDevice info:
| |
|
Note, that in the above, "exitCode" and "status" are always required and a date value passed must always be in ISO-8601 format. Also, it may seem like device_id is a challenge to set, because it would be different every time, but this is where the beauty of passing FileWave data elements in a script comes in. If you simply pass %device_id% as a Launch Argument to your fileset script, then that valueID can be readsupplied dynamicallyas inLaunch yourArguments, however, for security reasons it is better to supply the token as an Environment variable. When targeting Internal Names of Custom Fields (as either Launch Arguments or Environment Variables), surround the Internal Name with % symbols.
The start of a macOS script andmay substitutedlook with the specific Device ID of the current device. See below, where %device_id% is read by the PowerShell script as $args[0]. In a mac shell script this same variable would be used as $1 in the script:like:
Practical Examples (differing data types):
Using %device_id% as a Launch Argument.
|
| |||
|
| |||
|
|
SSL Certificate Problem
Self-Signed certificates may produce an error around SSL Certificates. Please act accordingly, based uponby the script
output,