Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
@planningcenter/api-client
Advanced tools
A Planning Center JavaScript API client that will make you smile
A javascript library that provides a client for interacting with Planning Center's Graph API as well as helper methods for transforming request and response data.
View the classic README here.
yarn add @planningcenter/api-client
import { Client } from "@planningcenter/api-client"
const client = new Client({ app: "services", version: "2018-11-01" })
client.get({
url: '/plans',
data: {
fields: {
Plan: ['dates', 'series', 'title'],
},
}
})
Client request methods will return a promise. When the promise is resolved, you'll be left with a transformed response (see below).
When making a request, the client will enforce the use of sparse fieldsets which requires the fields
key.
client.get({
url: '/plans',
data: {
where: { title: 'Plan Title' },
include: ['series'],
order: 'created_at',
fields: {
Plan: ['dates', 'series', 'title'],
Series: ['title', 'artwork_for_dashboard']
},
}
})
🚨 NOTE: When including records you also need to define the relation in fields
. See the usage of 'series'
above.
The default value of perPage
is 100
. You can adjust this value in the data
attribute:
client.get({
url: '/plans',
data: {
perPage: 25,
fields: {
Plan: ['title'],
},
}
})
If you need to return all results from a collection, instead of only the first page of results, you can include the walk: true
attribute inside the data
attribute:
client.get({
url: '/plans',
data: {
walk: true,
fields: {
Plan: ['title'],
},
}
})
This can be used in combination with perPage
to make many smaller requests for a large collection of data.
client.patch({
url: `/series/${seriesId}`,
data: {
fields: { Series: 'title,artwork_for_dashboard' },
data: { type: 'Series', attributes: { name: 'New Series Name' }
}
})
client.post({
url: '/series',
data: {
fields: { Series: 'title,artwork_for_dashboard' },
data: {
type: 'Series',
attributes: { name: 'New Series Name' },
relationships: {
plan: {
data: { type: 'Plan', id }
}
}
}
}
})
client.delete({ url: `/series/${seriesId}` })
The Client
class will automatically transform request and response data, but helpers for transforming data are also available to be used manually.
transformRequestData
Takes an object with camelCase request parameters and transforms to a more api friendly format.
import { transformRequestData } from "@planningcenter/api-client"
transformRequestData({
fields: { Song: ["title", "arrangements"], Arrangement: ["name"] },
include: "arrangements",
where: { title: "I Like Bugs" },
})
{
"fields[Song]": "title,arrangements",
"fields[Arrangement]": "name",
include: "arrangements",
per_page: 100,
"where[title]": "I Like Bugs",
}
transformResponse
Takes an JSON API spec-adhering response and transforms it to a more appropriate format for JavaScript.
import { transformResponse } from "@planningcenter/api-client"
transformResponse({
"data": {
"type": "Person",
"id": "123",
"attributes": {
"first_name": "Marvin",
"last_name": "Gaye"
},
"relationships": {
"top_song": {
"data": {
"type": "Song",
"id": "456"
}
},
"instruments": {
"data": [{
"type": "Instrument",
"id": "789"
}]
}
},
"links": { ... }
},
"included": [
{
"type": "Instrument",
"id": "789",
"attributes": {
"name": "Piano"
}
}
],
"meta": {
"parent": {
"id": "1",
"type": "Organization"
}
}
})
{
data: {
// string IDs are parsed into integers
id: 123,
type: "Person",
// all keys are camel-cased
firstName: "Marvin",
lastName: "Gaye",
// belongs to relationships are given a singular foreign key property
topSongId: 456,
topSongType: "Song",
// relationships not also `included` are given a property with a null value
topSong: null,
// has many relationships are given a plural foreign key property
instrumentIds: [789],
// included records are gathered via relationships & placed in a collection:
instruments: [
{ id: 789, type: "Instrument", name: "Piano" },
],
links: {}
},
// response meta is available in case you need it
meta: { parent: { id: "1", type: "Organization" } }
}
Pull requests are welcome and encouraged! See the contributing guidelines for more information.
FAQs
A Planning Center JavaScript API client that will make you smile
We found that @planningcenter/api-client demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.