How to retrieve basic resource information

Welcome back to another CCB Tutorial.

This week’s tutorial is focused on answering basic questions about a resource listed in CCB.

Although CCB provides native capabilities for managing resources, today’s tutorial will focus on if you wanted to provide your own interface for listing resources.

From personnel types to sound systems to rooms and much more, there can be quite a few things to track and keep up with when managing resources in their entirety.

Today’s tutorial won’t necessarily go deep in terms of the use, but I’ll share with you how to access resource information via the CCB API.

Setup variables and comments

Using the text editor of your choice, create and save the following php file: resource-list.php.

As with previous tutorials, be sure to include the following comments and file(s) as shown below. If you’re not familiar with the config.php file that’s included, then feel free to read previous tutorials or start here.

After comments and includes are defined, the next step is defining the apiService variable and setting it’s value equal to the following CCB api service: resource_list.

In addition, the resource_list CCB api service allows for optional parameters to be defined when executing the API call. I’ve commented out the following variables in the code above:

  • modDate variable is date last modified
  • page variable is the integer for pagination
  • perPage variable is the number of results return per api call on the page

For this tutorial, I chose to return ALL resources without using any optional parameters which I cover in the next section.

Prep for API call and parsing of response

It’s time to make the API call. But before we can execute the CCB API call, we must prepare and bind variables to their respective CCB API label for resource_list service.

As stated in the last section, there are optional parameters that help to limit the data return when retrieving resources via the CCB API. The respective parameters or labels for the CCB API service resource_list is as follows:

  • modified_since – the datetime since the last resources were modified.
  • page – provides pagination option should you have tens, hundreds or thousands of resources.
  • per_page – the number of resources returned on page when executing CCB api

To bind labels to their respective variables, create a urlData variable.  Set this variable equal to an encapsulated key-value pair array using PHP’s built-in array_filter method.

Also, the srv label should be bound to the apiService variable. I’ve included but commented out the other optional variables should you feel the need to use them in the future.

Data labels and variables are bound, and the CCB API call can be made using the ccbDetails function. Be sure to define the rss variable and set it equal to the ccbDetails function too.

As for the ccbDetails function, pass get as the first argument and the urlData variable as the second argument.

For more details about what ccbDetails function is and why it’s important, read here.

Parsing and display resource attributes

Now that you’ve successfully executed CCB API calls, it’s time we get down to parsing the data to make ready for web browser display.

To parse the response, we’ll use PHP’s built-in XPATH query method and the following expression: //resources/resource.

So, define a nodes variable, and set it equal to the rss variable pointed to use the aforementioned xpath query expression.

Now define an empty response_object variable to be used to capture and display parsed data points to the web browser.

We’re now ready to parse each room resource via the nodes variable. Create a foreach statement to iterate through each collected resource object, also known as the nodes variable.

Within the foreach statement, redefine the response_object variable to equal a string of concatenated files and html, using the “.=“ operator to concatenate each resource and its respective attributes.

Notice that I’ve provided the list of other resource attributes that you might find a good use for when building a custom app.

Also, the commented out variables may provide additional logic to display or not display certain resources and their attributes.

Finally, close the foreach statement and echo the response_object variable, and we’re done.

Time to test and display resources

For the sake of this tutorial, I only share how to access the resource data and not apply any sort of logic to displaying the data.

Again, with a few if statements, and use of optional parameters and returned attributes, you’re likely able to make this tutorial to another level.

By now, your code should look like the following in its entirety:

For now, save your code and open the file in a web browser. The results should look like the following:

There is so much more room for extending this tutorial, but I’m out of precious time today.

Stick around though, because we may reprise this tutorial as a future update.

Let me know if you have any questions or comments. See you next week.

Please comment if this tutorial has helped you.