Hey there, techies and non-techies alike! Let’s talk about event attendance.

Maybe you’ve tried tracking attendance for church events before, but life happened—technical glitches, busy schedules, or maybe you just plain forgot to set it up. Sound familiar?

Well, today’s your lucky day because I’m here to help you fix that once and for all!

In this tutorial, I’ll walk you through creating event attendance records in Church Community Builder (CCB) using PHP and XML. Trust me—it’s easier than it sounds, and we’ll have some fun along the way. Let’s get started!

🧰 What You’ll Need:

  • A text editor (Notepad++, Sublime Text, or even plain ol’ Notepad will do!)
  • A web server (Local like XAMPP or a live public one—your choice)
  • Basic PHP knowledge (Don’t worry; I’ll keep it beginner-friendly!)
  • Your CCB API credentials (username and password).

Ready? Let’s dive in.

Set Up Your PHP File

First things first, fire up your text editor and create a new file called create-event-attendance.php. Save it to your desktop or wherever your web server stores files.

Now, we’ll set up some variables to hold important info like your CCB domain, API credentials, and the API service we’ll use. PHP variables always start with a $, so keep that in mind!

Here’s what your file should look like:

<?PHP 

$churchdomain = 'example'; // Replace with your church's domain (without ".com") 
$apiUsername = 'ccbapiuser'; // Your CCB API username 
$apiPassword = 'p@55w0rd!'; // Your CCB API password 
$apiService = 'create_event_attendance'; // The API service we’ll use 

?>

🔑 Pro Tip: Make sure your variables match exactly—they’re case-sensitive!

Build the XML File

CCB’s API requires an XML file with specific details about the event. Think of it as the “recipe” for your attendance record. Create a new file called create-event-attendance.xml and add this structure:

Single Event Example:

<?xml version="1.0" encoding="UTF-8"?> 
<events> 
<event id="1453" occurrence="2024-11-17 10:00:00"> 
<did_not_meet>false</did_not_meet> 
<head_count>25</head_count> 
<attendees> 
<attendee id="3056" /> 
<attendee id="3057" /> 
</attendees> 
<topic>Sunday Service</topic> 
<notes>Great turnout, lots of new faces!</notes> 
<prayer_requests>Pray for Jane’s surgery next week.</prayer_requests> 
<info>Some attendees arrived late.</info> 
<email_notification>none</email_notification> 
</event> 
</events>

Multiple Events Example:

<?xml version="1.0" encoding="UTF-8"?>
<events>
<event id="1453" occurrence="2024-11-17 10:00:00">
<did_not_meet>false</did_not_meet>
<head_count>25</head_count>
<attendees>
<attendee id="3056" />
<attendee id="3057" />
</attendees>
<topic>Sunday Service</topic>
<notes>Great turnout, lots of new faces!</notes>
<prayer_requests>Pray for Jane’s surgery next week.</prayer_requests>
<info>Some attendees arrived late.</info>
<email_notification>none</email_notification>
</event>
<event id="1454" occurrence="2024-11-18 19:00:00">
<did_not_meet>false</did_not_meet>
<head_count>15</head_count>
<attendees>
<attendee id="3058" />
<attendee id="3059" />
</attendees>
<topic>Youth Night</topic>
<notes>Youth group had a blast!</notes>
<prayer_requests>Pray for Sam’s family during this tough time.</prayer_requests>
<info>Event ended early.</info>
<email_notification>none</email_notification>
</event>
</events>

Save this file in the same directory as your PHP file.

Create the cURL Call

Here’s where the proverbial magic happens! We’ll use PHP’s exec function and cURL to send your XML data to CCB’s API.

Add this code to your create-event-attendance.php file:

<?php

// Path to your XML file
$objData = “/path/to/your/create-event-attendance.xml”;

// Build the cURL command
exec(‘curl -u ‘.$apiUsername.’:’.$apiPassword.’ -F filedata=@”‘.$objData.'” “https://’.$churchdomain.’.ccbchurch.com/api.php?srv=’.$apiService.'”‘, $output, $result);

// Set a default error message
$msg = ‘ERROR: Event attendance not created.’;

// If the result is greater than 0, the cURL command succeeded
if ($result > 0) {
$msg = ‘SUCCESS: Event attendance created.’;
}

// Output the result
echo $msg;

?>

🔑 Important: Replace /path/to/your/create-event-attendance.xml with the actual path to your XML file.

Time to test it out!

Time to see your hard work in action! The completed create-event-attendance.phpfile  should look like the following:

<?PHP
$churchdomain = ‘example’; // your domain without the .com
$apiUsername = ‘ccbapiuser’; // your CCB api username
$apiPassword = ‘p@55w0rd!’; // your CCB api password
$apiService = ‘create_event_attendance’;
// Create the web url for the cURL call
$objData = $xmlFile = “/path/to/your/xml/file/create_attendance.xml”;s
// Create the cURL call with the respective variables and encapsulate it within an exec command
exec(‘curl -u ‘.$apiUsername.’:’.$apiPassword.’ -F filedata=@”‘.$objData.'” “https://’.$churchdomain.’.ccbchurch.com/api.php?srv=’.$apiService.'”‘,$output, $result);
// by default, error message is set as $msg variable
$msg = ‘ERROR: Event attendance not created.’
//if result is greater than 0, then the exec command was initiated successfully
if($result > 0){
$msg = ‘SUCCESS: Event attendance created.’;
}
// echo or print to the screen informing whether or not the event attendance was created in CCB
echo $msg;
?>

Place your files in the appropriate location:

  • For XAMPP users: Drop them into the htdocs folder and access them via http://localhost/create-event-attendance.php.
  • For a live server, upload the files to your root directory and use your domain to access them, like http://yourchurchdomain.com/create-event-attendance.php.

Run the script in your browser. If everything’s set up correctly, you’ll see one of these messages:

  • SUCCESS: Event attendance created.
  • ERROR: Event attendance not created.

Congrats! You’ve just mastered creating event attendance records using CCB’s API. Now, you can capture attendance for past and future events with ease.

Stay tuned for more tutorials and happy coding! 🚀

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...