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

1

2

3

4

5

6

7

8

<?PHP

// contains resusable globals and functions

include("includes/config.php");

$apiService='search_list';// CCB api service

?>

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.

1

2

3

4

5

6

7

8

9

<?PHP

$urlData=array_filter(array(

'srv'=>"$apiService"

));

$rss=ccbDetails('get',$urlData);// transform to XML

?>

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.

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.

1

2

3

4

5

6

7

8

9

10

11

12

<?PHP

$response_object='';

foreach($nodesas$node)

{

$response_object.=$node->name." (".$node['id'].") - Last Run: ".$node->last_run."<br/>";// now print the campus name (See CCB API documentation for more $apiService fields)

}

echo$response_object;

?>

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.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

<?PHP

// contains resusable globals and functions

include("includes/config.php");

$apiService='search_list';// CCB api service

$urlData=array_filter(array(

'srv'=>"$apiService"

));

$rss=ccbDetails('get',$urlData);// transform to XML

$nodes=$rss->xpath('//searches/search');// xpath for searches->search

$response_object='';

foreach($nodesas$node)

{

$response_object.=$node->name." (".$node['id'].") - Last Run: ".$node->last_run."<br/>";// now print the campus name (See CCB API documentation for more $apiService fields)