Hey there, my fellow CCB API-ers! Are you chomping at the bit to construct another exciting API tool?

Today, we’ll learn how to retrieve batch details using the Church Community Builder (CCB) REST API.

And for those of you who are new to CCBTutorials or coding, scripting, or programming in general, don’t worry at all. I’ll walk you through every step with easy-to-follow instructions.

Ready? Let’s dive in!

Beginning with the end in mind

First, what exactly are we trying to do? Simply put, this tutorial aims to fetch the details of a specific batch from the CCB API.

Think of it as looking up a transaction receipt—this could include dates, statuses, payment types, and more. It’s super handy for church admins or finance teams!

Setting Up the Basics

Before we get too far down the path in our development journey and in over our heads into the code, let’s ensure you have a few prerequisites ready:

  • A PHP environment: Localhost or a server with PHP installed.
  • CCB API credentials: You’ll need access to CCB and permission to fetch batch data.
  • A config file (config.php): This includes reusable functions for interacting with the CCB API. (We’ll assume you already have this set up.)

With these three steps checked off our list of prerequisites, let’s move forward, break ground, and start coding.

Using your text editor of choice, create a new PHP file named batch-profile-by-id.php and save it to your desktop or a web directory/folder.

Next, copy, paste, and modify the code example. Here’s the PHP script we’ll use to fetch batch details:

<?PHP

/** * Fetch Batch Details by ID */ 
// Step 1: Include configuration for API credentials and functions 
include("includes/config.php"); 

// Step 2: Define the API service and batch ID 
$apiService = 'batch_profile_from_id'; // CCB API service name 
$batchId = '24'; // Replace with the actual batch ID you want to retrieve 

// Step 3: Build the API request parameters 
$urlData = array_filter(array( 'srv' => $apiService, // Service name 'id' => $batchId // Batch ID )); 

// Step 4: Fetch data using a custom function `ccbDetails` 
$rss = ccbDetails('get', $urlData); // Makes the API call and returns XML 

// Step 5: Parse the XML response 
$nodes = $rss->xpath('//batches/batch'); // Navigate the XML to locate batch info 

// Step 6: Display the results print_r($nodes); // Output batch details for review

?>

Ok, let’s break this code down step by step.

Step-by-Step Code Breakdown

Without getting into the weeds of details or off the beaten code path we’re on, here’s a simple breakdown of what each part of the code does:

  1. Include Configuration:
    The config.php file handles authentication and reusable functions. Think of it as the backstage crew making everything work seamlessly.
  2. Define the Service and Batch ID:
    We specify the API service (batch_profile_from_id) and the unique batch ID we want to query.
  3. Build Request Parameters:
    Using array_filter, we prepare the parameters to send to the API. Each API request requires specific data. Here, we’re sending the service name (srv) and batch ID (id).
  4. Fetch Data with ccbDetails:
    This custom function makes the API call and retrieves the response. It’s our wrapper for cURL to communicate with the CCB API.
  5. Parse the XML Response:
    Using xpath, we extract the batch details from the XML response.
  6. Display Results:
    The print_r function shows the extracted data. This is for debugging or verifying the output.

Do you see what I see?

Now that you have the script and a step-by-step breakdown of each step let’s put it together and test your technical prowess.

If you’re using XAMPP, you’ll want to place this file in your htdocs folder and access it using localhost (e.g., http://localhost/batch-profile-by-id.php).

If you’re using a third-party web hosting provider, you’ll want to upload the file to your root web directory folder and access it using the domain or IP address of your web server (e.g., http://10.23.12.23/batch-profile-by-id.php or http://yourdomain.com/batch-profile-by-id.php).

Congratulations! You should now be able to execute the script and view the batch data details captured in your CCB system.

Stay tuned, and look out for future CCB API tutorials. Happy CCB API scripting! 💻

Related Posts

Subscribe and receive the following...

  • Inside CCB tips and tricks
  • Instant CCB tutorial alerts and updates
  • CCB How To's, Videos, Webinars and more...