Have you ever had a need to mass update CCB profile data for an individual(s) or family profiles?

Of course you could simply use the native CCB functionality and manually update CCB profile data for individuals or families one at a time.  Ouch!  One at a time, really?

Maybe a handful, but what if you’re wanting to update membership status, family position or any other mass update field your church uses.  Exactly, one by one ain’t gonna cut it!

But don’t fret, because there is hope.  Today’s tutorial will show you step-by-step how to use the CCB API to update profile data.

For the sake of the example, I’ll show you have to update a single profile so that you get the gist of the various moving pieces.

To be honest, we’re building upon the previous tutorials and modifying a few key items.  Let’s get started!

Using CCB’s Update Individual Service

You’ll want to get acclimated to the CCB API Documentation to start with.  To update profile data, we’ll use the update_individual api service.  Find this service in the CCB API documentation.

Often times, when you’re retrieving information using the CCB API, the request that is made is a GET request.  You will not be able to use a GET request to update profile data as you will need to make a POST request (referred to as HTTP POST in CCB API Documentation).

Using the code below, you’ll assign the apiService variable the update_individual value.

Next, specify the one required parameter to update profile data: individual_id. In the example, I assign a personid variable a value of 3224.  Replace 3224 with the exact individual id of the person you’re wanting to update their profile data.

If you don’t know how to find the individual id for a person in CCB, view the edit profile page screenshot below for alvin brown.  Notice the edit profile page’s url for a person has an individual_id parameter that is equal to 3224.

Screen Shot 2015-12-02 at 9.28.34 PM

Now that the required field, individual_id, has been assigned as a value to the personid variable, you’re ready to start assigning variables for the various fields you would like to update.

I’m not covering all of the fields that can be updated.  CCB’s API documentation does a good job of listing in detail which parameters can be submitted to update profile data.

For the sake of time, I’m only going to update the last name.  As you can see in the code, I assigned the value Browner to the lastname variable.

Again, per the CCB API documentation for update_individual service, you can assign more variables and their respective values.

Binding and prepping the URL data for CCB API call

Moving right along, you’re ready to bind variables and values to their respective API parameter names.  To bind variables and values, create two different variables: servData and urlData.

The servData variable contains the following binded service API parameters and values:

  • srv binds to the apiService variable
  • individual_id binds to the personid variable

Just as in previous tutorials, assign a urlData variable and assign it an array of binded service API parameters and values:

  • last_name binds to the lastname variable

If you have more fields to update, you’ll need to add variable and service parameter bindings for each one added.

Now were ready to pass both servData and urlData variables as an argument to the ccbDetails function we created in previous tutorials.

To do so, create a rss variable and assign it the ccbDetails function, making the first argument post in single quotes, urlData as second argument and servData as third argument.  Make sure the first argument is post and not get.

If this is your first tutorial, I highly encourage you to read the nitty gritty details the ccbDetails function. The ccbDetails function, when successfully executed, will return properly structured and formatted XML response.

Now we’re ready for our last step which is parsing the XML response.

Parsing update profile data XML response

The CCB API documentation provides request and XML response examples that can guide you as it pertains to knowing what fields exist in the XML response to be parsed.

Just like previous tutorials, use the XPATH query expression //individuals/individual to parse the XML Response.  Once assigning the XPATH query to the rss variable, then we’re ready for a good ole’ foreach statement to prepare the response_object variable results to be echoed to the web browser — we’re displaying the individual’s full name and age in this example.

And that’s it!  You’ve just successfully updated CCB profile data for an individual using the CCB API.

Now open a text editor of your choice and assemble your code, creating and saving a update-profile-data.php file that looks like the codebase below.  You’re now ready to copy, paste and test the file via a web browser or command line, if you know how.

Time to put it all together and test the codebase

Again, this code example only updates a single individual’s profile data.  But wait, there’s more…

I won’t cover it in this tutorial, but in the coming weeks, I’ll show you how to combine CCB API searching with the update_individual service to update multiple CCB profiles.  I’ll also create a parse and update multiple CCB profiles tutorial for those of you who use flat files such as excel, .csv or .txt. For both, we’ll build and extend the tutorial How to Search for Individuals – Part II.

Do let me know if you have issues, and/or comments.  Stay tuned for next week’s tutorial.

<?PHP

// contains resusable globals and functions
include("includes/config.php");

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

$personid = '3224';
$lastname = 'Browner';  // sample field to search for (See CCB API documentation for more $apiService fields)

$servData = array_filter( array(
	'srv' => "$apiService",
	'individual_id' => "$personid"
	) );

$urlData = array_filter( array(
'last_name' => "$lastname"
	) );

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

$nodes = $rss->xpath('//individuals/individual');  // xpath for individuals->individual

$response_object = '';

foreach ($nodes as $node)
{
    $response_object .= $node->full_name.' ('.$node['age'].')'."<br/>";  // now print the person's full name and age (See CCB API documentation for more $apiService fields)
}

echo $response_object;

?>

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