Jump to content

Pass Variable from RestAPI to Inventory Query Script


aldn-bnk

Recommended Posts

Hi Team,

I created an queries with goal is get the devices detail information base on their serial number. I saw the guidance from this KB https://fwkb.atlassian.net/wiki/spaces/KB/pages/4328035/RESTful+API#RESTfulAPI-BreakingdowntheJSON%2FResults

Then I tried to pass the variable from RestAPI to the queries but the result still failed, like the parameter doesn't success passed to the queries.

Is it any same case like me? 

Thanks

image.png

Screenshot 2023-04-17 at 16.03.15.png

Link to comment
Share on other sites

6 hours ago, AnEngelsen said:

@aldn-bnk

What are you trying to achieve using the FileWave API?

For example, Are you trying to access the results of an inventory query?
Or are you trying to access a specific piece of information about a client (based on the device serial number)?

 

Hi @AnEngelsen,

My goals is to access a specific piece of information about a client based on the device serial number.
Because on the KB page, there is no information or sample if I want to search the device by serial number

Link to comment
Share on other sites

Based on what I'm seeing in the API docs (https://FileWaveServer_URLGoesHere/api/doc/), the FileWave API requires you to provide the ClientID or DeviceID to perform a device lookup. (You cannot pass the serial number as the unique identifier.)

That said, you might be able to build an inventory query that contains that device serial number and the piece of information you want to capture.

Then you would use the API to reference the inventory query (and the resulting inventory data): https://fwkb.atlassian.net/wiki/spaces/KB/pages/4328035/RESTful+API#RESTfulAPI-Commands

 

  • Like 1
Link to comment
Share on other sites

  • Moderators

This isn't entirely correct.

FileWave has two different APIs

  • Command line - has existed for years and may run queries
  • Web - Created when we introduced the Web Admin and may do much more

The Web Admin API relies upon Client ID when attempting to reference devices directly, but as suggested if you build out a query in advance you may then interrogate the query for details.  You may even use this API to create a query

The command line API on the other hand can be provided a query and return results without it actually creating a new query in the database.  As such, you can build out anything you can akin to using the FileWave Central (Admin) App Inventory Query and the result should be posted back.

Here is an example query using the Command Line API:

#!/bin/zsh

query='{"criteria":{"column":"serial_number","component":"Client","operator":"is","qualifier":'\"$serial_number\"'},"fields":[{"column":"device_name","component":"Client"},{"column":"type","component":"OperatingSystem"}],"main_component":"DesktopClient"}'

curl -k -s -H "Authorization: $auth" https://$server_dns:20443/inv/api/v1/query_result/ --data $query -H "Content-Type: application/json"

This example will report the Device Name and OS Type for the defined serial number and is the same as the following (I've put an exact serial_number in the GUI example to make it easier to see:

image.png.5dc0569d47a276c90b387df042e004fc.png

image.png.6c3c50f0b3295f1df86cb1ffc8a41013.png

If you don't know the component names and types, then use the Web Admin API Docs to find them out.  Build out a query, save it then use the API doc to report all queries:

image.png.3d5a2150b8cf88bc60882a3ae35d1a86.png

Find your query in the list (if you just created it, it will be at the bottom), e.g.

  {
    "id": 253,
    "name": "OS Type",
    "favorite": true,
    "group": null,
    "version": 4
  }

Then use the API  Doc again to examine the query:

image.png.adf11bee44ee7938884225f83ea9ddcd.png

{
  "criteria": {
    "column": "serial_number",
    "component": "Client",
    "operator": "is",
    "qualifier": "C02Z90WDLVDQ"
  },
  "favorite": true,
  "fields": [
    {
      "column": "type",
      "component": "OperatingSystem"
    }
  ],
  "main_component": "DesktopClient",
  "name": "OS Type",
  "id": 253,
  "version": 4,
  "group": 0
}

Note the URL paths between Web Admin and Command Line differ.

Hopefully that is enough information for you to achieve your goal.

  • Like 2
Link to comment
Share on other sites

On 4/20/2023 at 7:41 PM, Sean said:

This isn't entirely correct.

FileWave has two different APIs

  • Command line - has existed for years and may run queries
  • Web - Created when we introduced the Web Admin and may do much more

The Web Admin API relies upon Client ID when attempting to reference devices directly, but as suggested if you build out a query in advance you may then interrogate the query for details.  You may even use this API to create a query

The command line API on the other hand can be provided a query and return results without it actually creating a new query in the database.  As such, you can build out anything you can akin to using the FileWave Central (Admin) App Inventory Query and the result should be posted back.

Here is an example query using the Command Line API:

#!/bin/zsh

query='{"criteria":{"column":"serial_number","component":"Client","operator":"is","qualifier":'\"$serial_number\"'},"fields":[{"column":"device_name","component":"Client"},{"column":"type","component":"OperatingSystem"}],"main_component":"DesktopClient"}'

curl -k -s -H "Authorization: $auth" https://$server_dns:20443/inv/api/v1/query_result/ --data $query -H "Content-Type: application/json"

This example will report the Device Name and OS Type for the defined serial number and is the same as the following (I've put an exact serial_number in the GUI example to make it easier to see:

image.png.5dc0569d47a276c90b387df042e004fc.png

image.png.6c3c50f0b3295f1df86cb1ffc8a41013.png

If you don't know the component names and types, then use the Web Admin API Docs to find them out.  Build out a query, save it then use the API doc to report all queries:

image.png.3d5a2150b8cf88bc60882a3ae35d1a86.png

Find your query in the list (if you just created it, it will be at the bottom), e.g.

  {
    "id": 253,
    "name": "OS Type",
    "favorite": true,
    "group": null,
    "version": 4
  }

Then use the API  Doc again to examine the query:

image.png.adf11bee44ee7938884225f83ea9ddcd.png

{
  "criteria": {
    "column": "serial_number",
    "component": "Client",
    "operator": "is",
    "qualifier": "C02Z90WDLVDQ"
  },
  "favorite": true,
  "fields": [
    {
      "column": "type",
      "component": "OperatingSystem"
    }
  ],
  "main_component": "DesktopClient",
  "name": "OS Type",
  "id": 253,
  "version": 4,
  "group": 0
}

Note the URL paths between Web Admin and Command Line differ.

Hopefully that is enough information for you to achieve your goal.

Hi @Sean,

Thank you so much for your kindly clear information and advise.

Your advise is what I want to achieve it.

Now I can use API for searching Device using S/N.

Thanks

  • Like 1
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...