PHPackages                             smadeira/planning-center-api - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. smadeira/planning-center-api

ActiveLibrary[API Development](/categories/api)

smadeira/planning-center-api
============================

PHP API wrapper for the Planning Center JSON API

v4.0.0(4y ago)111237[1 PRs](https://github.com/smadeira/planning-center-api/pulls)MITPHPPHP &gt;=7.3.0

Since Apr 8Pushed 3y ago3 watchersCompare

[ Source](https://github.com/smadeira/planning-center-api)[ Packagist](https://packagist.org/packages/smadeira/planning-center-api)[ RSS](/packages/smadeira-planning-center-api/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (16)Used By (0)

Planning Center API Wrapper
---------------------------

[](#planning-center-api-wrapper)

A PHP wrapper to access Planning Center data.

Installation
------------

[](#installation)

### Include the Package

[](#include-the-package)

This package is installed via Composer and the following assumes you have installed and initialized Composer for the project. Please refer to the [Composer](http://getcomposer.org) web site for help on getting composer installed and your initial composer.json created.

To add the Ministry Platform API to your project, simply require this package:

```
composer require smadeira/planning-center-api
```

Or, you can edit your composer.json file directly to add the Ministry Platform API:

```
"require": {
        "php": ">=7.0.0",
        "smadeira/planning-center-api": "^2.0.0"
    },

```

### Update the package

[](#update-the-package)

After including the API Wrapper with composer, do a composer update to download the dependencies required for the API wrapper to function.

```
composer update

```

The update command will download all the dependencies (including the API wrapper code) to the vendor diretory. Once this is done, you are ready to start development.

Mote: It's a good idea to run "composer update" every so often to download the latest version of the API wrapper and all of its dependencies. That's the beauty of Composer. It manages all of that for you so you don't have to.

Configuration
-------------

[](#configuration)

There are a few things that need to be done to configure the API wrapper to function in your environment.

### Connection Parameters

[](#connection-parameters)

This package makes use of vlucas/phpdotenv to manage configuration variables. In the root of your project, create a .env file with the following contents. Ensure you are using the correct URIs, client ID and secret for your installation.

```
# Planning Center API Parameters
PCO_APPLICATION_ID=YOU_PCO_APPLICATION_ID
PCO_SECRET=YOUR_PCO_SECRET

```

### Loading the API Wrapper

[](#loading-the-api-wrapper)

At the top of your code you will need to do a couple things to get access to the API Wrapper. You need to include autoload capabilities and load the config settings from the .env file

This is an example of what the top of a script might look like.

```
require_once __DIR__ . '/vendor/autoload.php';

use PlanningCenterAPI\PlanningCenterAPI as PCO;

// Get environment variables
$dotenv = Dotenv\Dotenv::createUnsafeImmutable(__DIR__);
$dotenv->load();
```

Usage
-----

[](#usage)

Usage is straight forward. Construct and execute your request.

### Execute select query

[](#execute-select-query)

The API Wrapper uses the same syntax and format as the online Planning Center API page. To execute a simple query you define the various components and execute. This sample will get all of the People in the People module (currently supports People and Services) with a last name of Smith and includes references to their addresses, emails and phone numbers. It is sorted in descending order of last name (Z - A)

```
// Get all people named Smith and sort by first name in descending order.  Then, print the results in array format (you would do additional processing
// of the data depending on your needs.

$pco = new PCO();

$people = $pco->module('people')
            ->table('people')
            ->where('last_name', '=', 'Smith')
            ->includes('addresses,emails,phone_numbers')
            ->order('-first_name')
            ->get();

(!$people) ? print_r( $pco->errorMessage() ) : print_r($people);
```

### The whole script

[](#the-whole-script)

Here is the whole script...

```
