REST API - Session Relevance Query - Struggling with query (Answered)

Hi All

I’m trying to get some properties to all report on a single row, but I’m struggling. The issue is there are multiple of some times of property for a bes computer, such as the IP address. I’m trying to get a single string out like this:

devicename~ipaddresses

I started with this query (the actual query is longer, but these are the key bits):

(name of it,
(values of results from (bes property whose (name of it = “IP Address”)) of it)
)
of bes computers

which outputs the following:

LT00001, 10.0.0.1
LT00001, 10.0.0.2
PC00001, 10.0.0.3
SV00001, 10.0.0.4

I then managed to get the multiple IP addresses to be concatenated with this script:

(name of it,
((concatenation " : " of values of it as string | “”) of results from (bes property whose (name of it = “IP Address”)) of it)
)
of bes computers

which outputs the following:

LT00001, 10.0.0.1 : 10.0.0.2
PC00001, 10.0.0.3
SV00001, 10.0.0.4

But I want to append the name and the IP addresses into a single string, using the &, such as:

(name of it &
((concatenation " : " of values of it as string | “”) of results from (bes property whose (name of it = “IP Address”)) of it)
)
of bes computers

But this returns ‘Error: A singular expression is required.’, and I do not know how to structure the query to avoid this error. I understand what the error means, there are multiple objects returned and I’m referencing them as a singular item, but I expected the concatenation to deal with this. How can I change my query to append both the computer name and list of IP addresses into a single string?

Thanks in advance.

Cheers

Gary

Hey Gary,

Probably not the optimal way to get what you want to achieve, but this is functional:

(item 0 of it & " " & item 1 of it) of (name of it, ((concatenation " : " of values of it as string | "") of results from (bes property "IP Address") of it)) of bes computers
1 Like

Thanks @eoin, I’ll give that a go. :smile:

For reference, if anyone is interested, this is the session relevance query I was working towards. This is working for me now. I output as XML fragments as it is nice and easy to parse within .NET. I have to filter out some values such as:

<none>

as it breaks the XML format. Anyway, hopefully someone will find this useful.

("<Item>" &
  "<ComputerName>" & item 0 of it & "</ComputerName>" &
  "<LastSeen>" & item 1 of it  & "</LastSeen>" &
  "<IpAddress>" & item 2 of it & "</IpAddress>" &
  "<LicenseType>" & item 3 of it & "</LicenseType>" &
  "<DeviceType>" & item 4 of it & "</DeviceType>" &
  "<Domain>" & item 5 of it & "</Domain>" &
  "<Make>" & item 6 of it & "</Make>" &
  "<Model>" & item 7 of it & "</Model>" &
  "<ComputerType>" & item 8 of it & "</ComputerType>" &
  "<IsLaptop>" & item 9 of it & "</IsLaptop>" &
  "<DnsName>" & item 10 of it & "</DnsName>" &
  "<OsSmall>" & item 11 of it & "</OsSmall>" &
  "<OsFull>" & item 12 of it & "</OsFull>" &
  "<OsVer>" & item 13 of it & "</OsVer>" &
  "<Ram>" & item 14 of it & "</Ram>" &
  "<CpuSpeed>" & item 15 of it & "</CpuSpeed>" &
  "<CpuName>" & item 16 of it & "</CpuName>" &
  "<CpuLogicalCount>" & item 17 of it & "</CpuLogicalCount>" &
  "<CpuCoreCount>" & item 18 of it & "</CpuCoreCount>" &
  "<CpuCoreCount2>" & item 19 of it & "</CpuCoreCount2>" &
  "<CpuPysicalCount>" & item 20 of it & "</CpuPysicalCount>" &
  "<User>" & item 21 of it & "</User>" &
  "<BiosDate>" & item 22 of it & "</BiosDate>" &
  "<UserLang>" & item 23 of it & "</UserLang>" &
"</Item>")
of (
  name of it,
  (last report time of it as string | ""),
  ((concatenation " : " of values of it as string | "") of results from (bes property whose (name of it = "IP Address")) of it),
  (License Type of it | ""),
  (Device Type of it | ""),
  ((if it starts with "<" then "" else it) of value of results from (bes properties "Domain/Workgroup - Windows") of it | ""),
  ((if it starts with "<" then "" else it) of value of results from (bes properties "Computer Manufacturer - Windows") of it | ""),
  ((if it starts with "<" then "" else it) of value of results from (bes properties "Computer Model - Windows") of it | ""),
  ((if it starts with "<" then "" else it) of value of results from (bes properties "Computer Type") of it | ""),
  ((if it starts with "<" then "" else it) of value of results from (bes properties "Laptop - Windows") of it | ""),
  ((if it starts with "<" then "" else it) of value of results from (bes properties "DNS Name") of it | ""),
  (Operating System of it | ""),
  ((if it starts with "<" then "" else it) of value of results from (bes properties "Full Operating System Name and Service Pack Level - Windows") of it | ""),
  ((if it starts with "<" then "" else it) of value of results from (bes properties "OS Version Number - Windows") of it |     ""),
  ((if it starts with "<" then "" else it) of value of results from (bes properties "RAM") of it | ""),
  ((if it starts with "<" then "" else it) of value of results from (bes properties "CPU") of it | ""),
  ((if it starts with "<" then "" else it) of value of results from (bes properties "Brand String of CPU - Windows") of it | ""),
  ((if it starts with "<" then "" else it) of value of results from (bes properties "Number of Processors - Windows") of it | ""),
  ((if it starts with "<" then "" else it) of value of results from (bes properties "Number of Processor Cores - Windows") of it | ""),
  ((if it starts with "<" then "" else it) of value of results from (bes properties "Core Processor Count") of it | ""),
  ((if it starts with "<" then "" else it) of value of results from (bes properties "Physical Processor Count") of it | ""),
  ((if it starts with "<" then "" else it) of value of results from (bes properties "User Name") of it | ""),
  ((if it starts with "<" then "" else it) of value of results from (bes properties "BIOS") of it | ""),
  ((if it starts with "<" then "" else it) of value of results from (bes properties "User Language - Windows") of it | "")
)
of bes computers
4 Likes

It was requested that I provide an example of this query formatted for the web, so it can be used in a web browser or via the REST API. The query contains some characters that you cannot use in a standard URL string, so they need to be swapped out for tokens. This is the above query, which formats the output as XML, in the format of a URL string:

("<Item>" %26 "<ComputerName>" %26 item 0 of it %26 "<%2FComputerName>" %26 "<LastSeen>" %26 item 1 of it %26 "<%2FLastSeen>" %26 "<IpAddress>" %26 item 2 of it %26 "<%2FIpAddress>" %26 "<LicenseType>" %26 item 3 of it %26 "<%2FLicenseType>" %26 "<DeviceType>" %26 item 4 of it %26 "<%2FDeviceType>" %26 "<Domain>" %26 item 5 of it %26 "<%2FDomain>" %26 "<Make>" %26 item 6 of it %26 "<%2FMake>" %26 "<Model>" %26 item 7 of it %26 "<%2FModel>" %26 "<ComputerType>" %26 item 8 of it %26 "<%2FComputerType>" %26 "<IsLaptop>" %26 item 9 of it %26 "<%2FIsLaptop>" %26 "<DnsName>" %26 item 10 of it %26 "<%2FDnsName>" %26 "<OsSmall>" %26 item 11 of it %26 "<%2FOsSmall>" %26 "<OsFull>" %26 item 12 of it %26 "<%2FOsFull>" %26 "<OsVer>" %26 item 13 of it %26 "<%2FOsVer>" %26 "<Ram>" %26 item 14 of it %26 "<%2FRam>" %26 "<CpuSpeed>" %26 item 15 of it %26 "<%2FCpuSpeed>" %26 "<CpuName>" %26 item 16 of it %26 "<%2FCpuName>" %26 "<CpuLogicalCount>" %26 item 17 of it %26 "<%2FCpuLogicalCount>" %26 "<CpuCoreCount>" %26 item 18 of it %26 "<%2FCpuCoreCount>" %26 "<CpuCoreCount2>" %26 item 19 of it %26 "<%2FCpuCoreCount2>" %26 "<CpuPysicalCount>" %26 item 20 of it %26 "<%2FCpuPysicalCount>" %26 "<User>" %26 item 21 of it %26 "<%2FUser>" %26 "<BiosDate>" %26 item 22 of it %26 "<%2FBiosDate>" %26 "<UserLang>" %26 item 23 of it %26 "<%2FUserLang>" %26 "<%2FItem>") of (name of it, (last report time of it as string | "") , ((concatenation " : " of values of it as string | "") of results from (bes property whose (name of it = "IP Address")) of it) , (License Type of it | "") , (Device Type of it | "") , ((if it starts with "<" then "" else it) of value of results from (bes properties "Domain%2FWorkgroup - Windows") of it | "") , ((if it starts with "<" then "" else it) of value of results from (bes properties "Computer Manufacturer - Windows") of it | "") , ((if it starts with "<" then "" else it) of value of results from (bes properties "Computer Model - Windows") of it | "") , ((if it starts with "<" then "" else it) of value of results from (bes properties "Computer Type") of it | "") , ((if it starts with "<" then "" else it) of value of results from (bes properties "Laptop - Windows") of it | "") , ((if it starts with "<" then "" else it) of value of results from (bes properties "DNS Name") of it | "") , (Operating System of it | "") , ((if it starts with "<" then "" else it) of value of results from (bes properties "Full Operating System Name and Service Pack Level - Windows") of it | "") , ((if it starts with "<" then "" else it) of value of results from (bes properties "OS Version Number - Windows") of it | "") , ((if it starts with "<" then "" else it) of value of results from (bes properties "RAM") of it | "") , ((if it starts with "<" then "" else it) of value of results from (bes properties "CPU") of it | "") , ((if it starts with "<" then "" else it) of value of results from (bes properties "Brand String of CPU - Windows") of it | "") , ((if it starts with "<" then "" else it) of value of results from (bes properties "Number of Processors - Windows") of it | "") , ((if it starts with "<" then "" else it) of value of results from (bes properties "Number of Processor Cores - Windows") of it | "") , ((if it starts with "<" then "" else it) of value of results from (bes properties "Core Processor Count") of it | "") , ((if it starts with "<" then "" else it) of value of results from (bes properties "Physical Processor Count") of it | "") , ((if it starts with "<" then "" else it) of value of results from (bes properties "User Name") of it | "") , ((if it starts with "<" then "" else it) of value of results from (bes properties "BIOS") of it | "") , ((if it starts with "<" then "" else it) of value of results from (bes properties "User Language - Windows") of it | "")) of bes computers

So, as you can see, the following ASCII character tokens were used:

& is replaced with %26
/ is replaced with %2F

The tokens are the ASCII character codes in hex preceded with %, so 26 is the hex character code for &.

If this URL string is going to be used within a C# application (which is how I am using it), then to store this in a string, you need to escape the embedded quote characters with a backslash: "

I hope this is useful to someone :smile:

Cheers

Gary

2 Likes