planning center api for dart
planning center is an online platform for church management.
it provides multiple apps for things like check-ins, service planning, volunteer management, crm, giving and more.
plus, they provide a robust api to access nearly
every aspect of their system remotely.
features
this package provides code to interact with every single planning center app through the most current api version available (see the changelog).
currently, the package depends on an organization level developer key and secret that you can generate here:
planning center developer console.
todo: in the future, this library will support an oauth authentication flow.
getting started
install the package:
dart pub add planningcenter_api
usage
before you can access the planning center api, you need to initialize the library with an appid
and a secret
. then, you may access the api object directly with the static member planningcenter.instance
from which you can make api calls through planningcenter.instance.call(endpoint, httpverb, queryobject)
.
however, once the library has been initialized
if (planningcenter.initialized) ...
then, you can access the different applications by static methods on their classes directly or by calling methods on existing objects.
import 'dart:io'; // to exit the script faster
import 'dart:convert'; // for the pretty printing of json
import 'package:planningcenter_api/planningcenter_api.dart';
/// this is where i store my [appid] and [secret] constants
import '../secrets.dart';
/// this funciton might come in handy for you sometime :-)
string pretty(object obj) {
jsonencoder encoder = jsonencoder.withindent(' ', (obj) {
try {
return obj.tojson();
} catch (_) {
return obj.tostring();
}
});
return encoder.convert(obj);
}
/// here's the real example code
void main() async {
// begin by initializing the planningcenter api
planningcenter.init(appid, secret);
// now, all classes beginning with pco are available for use
/// get the service types on the default organization (defaults to grabbing 25)
/// will return list<pcoservicesservicetype>
var servicetypes = await pcoservicesservicetype.getmany();
if (servicetypes.isnotempty) {
var service = servicetypes.first;
print('found service type: ${service.name}');
/// most class instances have methods allowing you to fetch related items
/// this time, we also are using a query object to request plands in descending order
/// of their sort date
var plans = await service.getplans(query: planningcenterapiquery(order: '-sort_date'));
if (plans.isnotempty) {
var plan = plans.first;
print('found plan: ${plan.seriestitle} - ${plan.title} - ${plan.lasttimeat}');
var items = await plans.first.getitems();
for (var item in items) {
print('plan item: ${item.title}n${item.description}n');
if (item.title == 'change me') {
print('attempting to update this item');
item.title = 'changed';
var result = await item.save();
print(result ? 'successful' : 'not successful');
}
}
}
}
// to call the api directly, you can do this.
var res = await planningcenter.instance.call('/services/v2/songs');
print(pretty(res));
exit(0);
}
unimplemented so far
- oauth authentication
- support for api “actions”
- support for the “include” query parameter
Comments are closed.