BigFix API Query computers based on computer name

This is driving me crazy, how do I query the API for a list of computer IDs based on the first 4 of the computer name? I have tried so many different combinations over the last 4 hours and can not figure this out. Seems like it should be fairly straight forward. Please help!

$computers = Invoke-WebRequest -Credential $creds -Uri https://bigfix.spencerstuart.com:52311/api/query?relevance="(ids of it) of bes computers whose (name of it as string as uppercase starts with ‘QA00’)"

The above query returns a list of random numbers a sample of which is below. A sample computer ID that should be returned is 1822287 so none of the below numbers would correspond to what should be returned.

104
97
114
97
99
116
101
114
32
119
104
105
99
104
32
105
115
32
110
111
116
32
97
108
108
111
119
101
100
46
60
47
69
114
114
111
114
62
10
9
60
47
81
117
101
114
121
62
10
60
47
66
69
83
65
80
73
62
10

Thanks!
Tony

At first glance I don’t see a problem with your query. To troubleshoot I’d probably start by also returning the names of the computers that are being retrieved to see whether we can discern a pattern

(ids of it, names of it) of bes computers whose (name of it as string as uppercase starts with ‘QA00’)

Also check to be sure that your API credential has management rights to the computer, and that the computer properties in the console correctly show you as an operator. The client evaluates the admin rights as an action, so if this client is failing to gather or report then your api credential may not be able to query that particular machine.

I just tried with different admin credentials that should have rights to everything in BigFix… Here is the command and the complete output from it. I don’t get it… At the bottom I included the RawContent method which shows there is an error for invalid character, but unsure where.

PS C:\temp> $computers = Invoke-WebRequest -Credential $creds -Uri https://bigfix.spencerstuart.com:52311/api/query?relevance="(ids of it, names of it) of bes computers whose (name of it as string as uppercase starts with ‘QA00’)"
PS C:\temp> $computers.Content
60
63
120
109
108
32
118
101
114
115
105
111
110
61
34
49
46
48
34
32
101
110
99
111
100
105
110
103
61
34
85
84
70
45
56
34
63
62
10
60
66
69
83
65
80
73
32
120
109
108
110
115
58
120
115
105
61
34
104
116
116
112
58
47
47
119
119
119
46
119
51
46
111
114
103
47
50
48
48
49
47
88
77
76
83
99
104
101
109
97
45
105
110
115
116
97
110
99
101
34
32
120
115
105
58
110
111
78
97
109
101
115
112
97
99
101
83
99
104
101
109
97
76
111
99
97
116
105
111
110
61
34
66
69
83
65
80
73
46
120
115
100
34
62
10
9
60
81
117
101
114
121
32
82
101
115
111
117
114
99
101
61
34
40
105
100
115
32
111
102
32
105
116
44
32
110
97
109
101
115
32
111
102
32
105
116
41
32
111
102
32
98
101
115
32
99
111
109
112
117
116
101
114
115
32
119
104
111
115
101
32
40
110
97
109
101
32
111
102
32
105
116
32
97
115
32
115
116
114
105
110
103
32
97
115
32
117
112
112
101
114
99
97
115
101
32
115
116
97
114
116
115
32
119
105
116
104
32
226
128
152
81
65
48
48
226
128
153
41
34
62
10
9
9
60
82
101
115
117
108
116
62
60
47
82
101
115
117
108
116
62
10
9
9
60
69
114
114
111
114
62
84
104
105
115
32
101
120
112
114
101
115
115
105
111
110
32
99
111
110
116
97
105
110
101
100
32
97
32
99
104
97
114
97
99
116
101
114
32
119
104
105
99
104
32
105
115
32
110
111
116
32
97
108
108
111
119
101
100
46
60
47
69
114
114
111
114
62
10
9
60
47
81
117
101
114
121
62
10
60
47
66
69
83
65
80
73
62
10

PS C:\temp> $computers.RawContent
HTTP/1.1 200 OK
SessionToken: dmRhSWdITHExT3M4K2J4RDFjRTE1Zmcvd2dBNDBFL2Y1UzIzNHdVSUVoZVhzWGg0OXJNUTZKbkVxcTB2bXExV2xGN3E2ZkF1SW5uK2xjNjV0TGRZa3c9PQ==
Strict-Transport-Security: max-age=31536000; includeSubDomains
Transfer-Encoding: chunked
Set-Cookie: SessionToken=“vdaIgHLq1Os8+bxD1cE15fg/wgA40E/f5S234wUIEheXsXh49rMQ6JnEqq0vmq1WlF7q6fAuInn+lc65tLdYkw==”;Path=/api;Secure;HttpOnly;Max-Age=300;Expires=Fri, 15 Feb 2019 21:29:13 +0000;

<?xml version="1.0" encoding="UTF-8"?> This expression contained a character which is not allowed.

@tlitterio Try changing the single quotes around QA00 to double quotes.

It may work with this syntax

$computer = Invoke-WebRequest -Credential $creds -Uri "https://bigfix.spencerstuart.com:52311/api/query?relevance=(ids of it, names of it) of bes computers whose (name of it as string as uppercase starts with "QA00")"

(Note that before each " surrounding QA00 should be a ` backtick)

Or you can percent encode the " characters in the request

I have tried the command SLB recommended, with the ` before the "s and with %20 encoding and it just returns the same garbage listed above… I am at a loss… Has anyone else run into this? This seems like it should be fairly straight forward.

I’m not familiar enough with PowerShell at the moment, but this seems to be an artifact of the .Content method to read the $computer variable. The same happens to me with any query to /api/query. .RawContent worked better. And if you add &output=json as a query parameter, that might avoid the XML parsing error you reference above.

That said, I was able to get the expected output to a file by adding -outputfile <filename> to the Invoke-WebRequest command, and then referencing the file.

Invoke-WebRequest -skipcertificatecheck -Uri "https://bigfixvm:52311/api/query?relevance=names of bes computers&output=json" -credential $creds -outfile "R:\foo.txt"

Wow! That was it! I know I tried the .RawContent method before and it was the same as .Content but something in the above modifications must have changed it! Thanks!