PHPackages                             zwg/buttercms-php - 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. zwg/buttercms-php

ActiveLibrary[API Development](/categories/api)

zwg/buttercms-php
=================

ButterCMS PHP API Wrapper

3.0.2(2y ago)08PHPPHP &gt;=8.0

Since Jul 8Pushed 2y agoCompare

[ Source](https://github.com/zuzanawangle/buttercms-php)[ Packagist](https://packagist.org/packages/zwg/buttercms-php)[ RSS](/packages/zwg-buttercms-php/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (3)Versions (22)Used By (0)

ButterCMS PHP API Wrapper
=========================

[](#buttercms-php-api-wrapper)

This wrapper enables PHP developers to quickly and easily get up and running with [ButterCMS](https://buttercms.com/). It is based of off the [API documentation](https://buttercms.com/docs/api/).

Requirements
------------

[](#requirements)

PHP 5.3.0 and later.

Composer
--------

[](#composer)

You can install the bindings via [Composer](http://getcomposer.org/). Run the following command:

```
composer require buttercms/buttercms-php
```

To use the bindings, use Composer's [autoload](https://getcomposer.org/doc/00-intro.md#autoloading):

```
require_once('vendor/autoload.php');
```

Manual Installation
-------------------

[](#manual-installation)

If you do not wish to use Composer, you can download the [latest release](https://github.com/buttercms/buttercms-php/releases). Then, to use the bindings, include the `src/ButterCMS.php` file.

```
require_once('/path/to/buttercms-php/src/ButterCMS.php');
```

Authentication
--------------

[](#authentication)

By default the ButterCMS client expects a valid authentication token for all READ operations. For instructions on how to obtain a valid READ authentication token see the [API documentation](https://buttercms.com/docs/api/#authentication).

Optionally, the ButterCMS client additionally accepts a valid authentication token for all WRITE operations. For instructions on how to obtain a valid WRITE authentication token see the [API documentation](https://buttercms.com/docs/api/#write-authentication).

```
use ButterCMS\ButterCMS;

$butterCms = new ButterCMS(
    '',
    ''    // Optional
);
```

Pages
-----

[](#pages)

For a list of `params` see the [API documentation](https://buttercms.com/docs/api/?php#pages)

```
use ButterCMS\ButterCMS;

$butterCms = new ButterCMS('', '');

// Create a Page
$writeApiStatus = $butterCms->createPage($params);

// Fetch a Page
$page = $butterCms->fetchPage('about', 'welcome-to-the-site');

// Update a Page
$pageData = json_decode(json_encode($page), true);
$pageData['title'] = 'New Page Title';
$writeApiStatus = $butterCms->updatePage('welcome-to-the-site', $pageData);

// These are equivalent
echo $page->getFields()['some-field'];
echo $page->getField('some-field');

$pagesResponse = $butterCms->fetchPages('news', ['breaking-news' => true]);
var_dump($pagesResponse->getMeta()['count']);
foreach ($pagesResponse->getPages() as $page) {
    echo $page->getSlug();
}
// Error Handling
try {
    $butterCms->fetchPage('about', 'non-existent-page');
} catch (GuzzleHttp\Exception\BadResponseException $e) {
    // Happens for any non-200 response from the API
    var_dump($e->getMessage());
} catch (\UnexpectedValueException $e) {
    // Happens if there is an issue parsing the JSON response
    var_dump($e->getMessage());
}
```

Collections
-----------

[](#collections)

For a list of `params` and functionality see the [API documentation](https://buttercms.com/docs/api/#collections)

```
use ButterCMS\ButterCMS;

$butterCms = new ButterCMS('', '');

$writeApiStatus = $butterCms->createCollectionItem('collection_key', [
    'status' => 'published',
    'fields' => [
        [
          'field1_key': 'Field value',
          'field2_key': 'Field value',
        ]
    ]
]);

// Get list of specific collections
$collectionsResponse = $butterCms->fetchCollections(['collection_key'], ['locale' => 'en']);

// Get a collection from the list
$collection = $collectionsResponse->getCollection('collection_key');

// Get collection items
$items = $collection->getItems();

// Update a specific item
$item = $items[0];
$itemData = json_decode(json_encode($item), true);
$itemData['fields']['field1_key'] = 'New field value';
$writeApiStatus = $butterCms->updateCollectionItem($collection->getKey(), $item->getId(), $itemData);

// Delete a specific item
$deleteSuccess = $butterCms->deleteCollectionItem($collection->getKey(), $item->getId());

// Legacy - deprecated
$contentFields = $butterCms->fetchContentFields(['collection_key'], ['locale' => 'en']);
```

Blog Engine
-----------

[](#blog-engine)

For a list of `params` see the [API documentation](https://buttercms.com/docs/api/?php#blog-engine)

```
use ButterCMS\ButterCMS;

$butterCms = new ButterCMS('', '');

// Posts
$result = $butterCms->fetchPosts(['page' => 1]);

$meta = $result->getMeta(); // Meta information like pagination
print_r($meta);

$posts = $result->getPosts(); // Get posts array off of result

$post = $posts[0]; // Get the first post
echo $post->getTitle(); // Access attributes using getXxxx() format.
echo $post->getSlug();

$author = $post->getAuthor(); // Access nested objects: Author, Tags, Categories like so
echo $author->getFirstName();
echo $author->getLastName();

// Loop through posts
foreach ($posts as $post) {
    echo $post->getTitle();
}

// Create a Post
$writeApiStatus = $butterCms->createPost($params);

// Query for one post
$response = $butterCms->fetchPost('post-slug');
$post = $response->getPost();
echo $post->getTitle();

// Update a Post
$postData = json_decode(json_encode($post), true);
$postData['title'] = 'New Post Title';
$writeApiStatus = $butterCms->updatePost('post-slug', $postData);

// Authors
$butterCms->fetchAuthor('author-slug');
$butterCms->fetchAuthors(['include' => 'recent_posts']);

// Categories
$butterCms->fetchCategory('category-slug');
$butterCms->fetchCategories(['include' => 'recent_posts']);

// Tags
$butterCms->fetchTag('tag-slug');
$butterCms->fetchTags();

// Feeds - returns a SimpleXMLElement object
$feed = $butterCms->fetchFeed('rss');

// Search
$butterCms->searchPosts('query', ['page' => 1]);
```

### Other

[](#other)

View PHP [Blog engine](https://buttercms.com/php-blog-engine/) and [Full CMS](https://buttercms.com/php-cms/) for other examples of using ButterCMS with PHP.

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~161 days

Recently: every ~171 days

Total

17

Last Release

1062d ago

Major Versions

1.0.3 → 2.0.02017-03-21

2.5 → 3.0.02022-09-21

PHP version history (2 changes)1.0.0PHP &gt;=5.3.0

3.0.0PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/6293c940cfbcca1880c12a9d13f272e2ae1ac8166b77b9dad3bc0f7d96eb11b1?d=identicon)[zuzana.buriana](/maintainers/zuzana.buriana)

---

Top Contributors

[![joshholat](https://avatars.githubusercontent.com/u/477603?v=4)](https://github.com/joshholat "joshholat (32 commits)")[![jakelumetta](https://avatars.githubusercontent.com/u/160873?v=4)](https://github.com/jakelumetta "jakelumetta (15 commits)")[![chasecoleman](https://avatars.githubusercontent.com/u/17017356?v=4)](https://github.com/chasecoleman "chasecoleman (7 commits)")[![stevenmaguire](https://avatars.githubusercontent.com/u/1851973?v=4)](https://github.com/stevenmaguire "stevenmaguire (5 commits)")[![zuzana-burianova](https://avatars.githubusercontent.com/u/99146730?v=4)](https://github.com/zuzana-burianova "zuzana-burianova (2 commits)")[![orlyohreally](https://avatars.githubusercontent.com/u/17960784?v=4)](https://github.com/orlyohreally "orlyohreally (1 commits)")[![Past9](https://avatars.githubusercontent.com/u/7954699?v=4)](https://github.com/Past9 "Past9 (1 commits)")[![rogerjin12](https://avatars.githubusercontent.com/u/23621652?v=4)](https://github.com/rogerjin12 "rogerjin12 (1 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")[![comanche](https://avatars.githubusercontent.com/u/1100167?v=4)](https://github.com/comanche "comanche (1 commits)")

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/zwg-buttercms-php/health.svg)

```
[![Health](https://phpackages.com/badges/zwg-buttercms-php/health.svg)](https://phpackages.com/packages/zwg-buttercms-php)
```

###  Alternatives

[statamic/cms

The Statamic CMS Core Package

4.8k3.6M985](/packages/statamic-cms)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3741.3M47](/packages/tencentcloud-tencentcloud-sdk-php)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k656.1k38](/packages/neuron-core-neuron-ai)[avalara/avataxclient

Client library for Avalara's AvaTax suite of business tax calculation and processing services. Uses the REST v2 API.

528.5M7](/packages/avalara-avataxclient)[eslazarev/wildberries-sdk

Wildberries OpenAPI clients (generated).

273.0k](/packages/eslazarev-wildberries-sdk)[files.com/files-php-sdk

Files.com PHP SDK

2481.1k](/packages/filescom-files-php-sdk)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
