Displaying a list of last run save searches

Featured in Alltop

Today’s tutorial is a bit light since we’ve spent the last month or so doing a bit of heavy lifting completing the spiritual gifts assessment questionnaire.

Have you ever wanted to see when a saved search or report was last run? Or maybe you’re wanting another program to execute a CCB saved search.

I’ll show you how to create a list of saved searches, display the name, id and last run date, and use the CCB API service to do so.

Let’s jump in and get started.

Setup includes and variables

Open the text editor of your choice, naming and saving a php file search-list.php.

Just as we have performed with previous tutorials, include the config.php file.

Next, define the CCB API Service to be used. For this tutorial, we’re using the search_list api to access and return a list of saved searches in CCB.

If you’re unfamiliar with saved searches, then take a moment to read or watch CCB’s saved search video tutorial.

Define the apiService variable and set it equal to CCB’s API service search_list.

Time to bind variables and labels, and make CCB API make

Next, we’ll need to bind the apiService variable to the CCB API’s srv label for when me make the CCB API call.

To do this, create a urlData variable. Set this variable equal to an array of the srv label binded to the apiService variable, and encapsulated using PHP’s built-in array_filter method.

Once completed, we’re now ready to make the CCB API call. To do so, define a rss variable and set it equal to the ccbDetails function, passing ‘get’ as the first argument and the urlData variable as the second argument.

To learn more about the PHP magic and heavy lifting of the ccbDetails function, click here.

Time to parse and display saved search information

We’ve successfully made the CCB API call to retrieve saved search data now transformed into an XML response.

To parse the XML response of saved search data, we’ll use PHP’s built-in xpath query method and the following expression: //searches/search.

Define the nodes variable and set it equal to the rss variable pointed to the xpath query as shown below.

At this time, create an empty response_object variable. This variable is used to capture saved search data, specifically the name, id and last run date for reach search.

To parse through each saved search row of data or array, create a foreach statement using the nodes variable.

Within the foreach statement, use the response_object variable and the “.=“ operator to concatenate and capture saved search data.

Finally, close the foreach statement and echo the response_object variable.

Bring it all together to test your coding chops

I told you today’s tutorial was light and easy in comparison to our last series. Get your rest while you can, because we’ll start another series and soon.

In the mean time, save your search-list.php file and open it in a web browser to test. You should see something like the following screenshot. Of course, your list is going to be unique to whatever saved searches are within your CCB account.

Nevertheless, you could easily have another 3rd party system now access your saved searches and their respective data. For more on executing searches, go here.

That’s it for today and this week. I look forward to seeing you back here for next week’s tutorial on using the CCB API to automate and integrate with 3rd party systems of your choice.

 


Please comment if this tutorial has helped you.