Custom Relevance errors

I am attempting to write some custom relevance to extract a list of applicable Fixlets per Computer, from BigFix. I need to extract this as a CSV so that it can be consumed by an external system. These are the data items I am trying to extract:

Computer ID, Fixlet Name, Source Release Date

I have developed some custom Relevance using the BigFix Session Relevance Tester:

(name of it, source release date of it) of relevant fixlets whose (display name of site of it = “Patches for Windows” AND fixlet flag of it AND (category of it = “Security Update” OR category of it = “Security Hotfix” OR category of it contains “Critical Update”)) of bes computers whose (id of it as string = “12763049”)

This works successfully within the Session Relevance Tester. However, if I try to use the BigFix API I get an error. I have tried using the /api/query resource:

api/query?relevance=(name+of+it,+source+release+date+of+it)+of+relevant+fixlets+whose+(display+name+of+site+of+it+=+“Patches%20for%20Windows”+AND+fixlet+flag+of+it+AND+(category+of+it+=+“Security%20Update”+OR+category+of+it+=+“Security%20Hotfix”+OR+category+of+it+contains+“Critical%20Update”))+of+bes+computers+whose+(id+of+it+as+string+=+“12763049”)

returns:

The operator "equal" is not defined.

Is this because I am trying to use Session Relevance, but the API query resource does not support Session Relevance?

Could anyone suggest a solution to this issue, or suggest any better method I could use to extract this data?

I think you got the URL encoding of the session relevance wrong (session relevance does work in RestAPI too) or at least that’s the case on the few browsers I tested it with. Try this (it works for me):

api/query?relevance=(name%20of%20it,%20source%20release%20date%20of%20it)%20of%20relevant%20fixlets%20whose%20(display%20name%20of%20site%20of%20it%20=%20%22Patches%20for%20Windows%22%20AND%20fixlet%20flag%20of%20it%20AND%20(category%20of%20it%20=%20%22Security%20Update%22%20OR%20category%20of%20it%20=%20%22Security%20Hotfix%22%20OR%20category%20of%20it%20contains%20%22Critical%20Update%22))%20of%20bes%20computers%20whose%20(id%20of%20it%20as%20string%20=%20%2212763049%22)

1 Like

Also, if you use the post method, you don’t have to worry about URL encoding the relevance string.

Thanks - this works perfectly.

For the POST method, do you have to specify the relevance clause as an XML document?

the output is a field you can specify. Here’s the code I use (no comments on php) :wink:

Also forgot that I do encode the relevance…

function CallAPIPostRelevance($url,$post_string, $output = "XML")
{
	global $RestUser;

	#'relevance' => urlencode($post_string)
	#'relevance' => $post_string
	$fields = array(
		'output' => $output,
		'relevance' => urlencode($post_string)
	);
	
	$fields_string = "";
	//url-ify the data for the POST
	foreach($fields as $key=>$value) 
	{ 
		$fields_string .= $key.'='.$value.'&'; 
	}
	rtrim($fields_string, '&');
	
	$ch = curl_init(); 
	curl_setopt($ch, CURLOPT_URL,$url); 
	curl_setopt($ch,CURLOPT_POST, count($fields));
	curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
	
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
	curl_setopt($ch, CURLOPT_TIMEOUT, 3600); #1 hour
	#curl_setopt($ch, CURLOPT_USERAGENT, $defined_vars['HTTP_USER_AGENT']);
    curl_setopt($ch, CURLOPT_USERAGENT, 'HTTP_USER_AGENT');
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
	
	curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
	curl_setopt($ch, CURLOPT_USERPWD, "$RestUser");
	
	curl_setopt($ch, CURLOPT_NOSIGNAL, 1);

	$data = curl_exec($ch); 
	
	return $data;
}