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

ActiveLibrary[API Development](/categories/api)

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

ButterCMS PHP API Wrapper

3.1.0(1y ago)41178.4k↑11.8%9PHPPHP &gt;=8.0

Since Jul 8Pushed 1y ago7 watchersCompare

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

READMEChangelog (10)Dependencies (3)Versions (20)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

49

—

FairBetter than 95% of packages

Maintenance39

Infrequent updates — may be unmaintained

Popularity44

Moderate usage in the ecosystem

Community22

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 ~181 days

Recently: every ~233 days

Total

18

Last Release

524d 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://avatars.githubusercontent.com/u/16144259?v=4)[ButterCMS](/maintainers/ButterCMS)[@ButterCMS](https://github.com/ButterCMS)

---

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)")[![prokopsimek](https://avatars.githubusercontent.com/u/5487217?v=4)](https://github.com/prokopsimek "prokopsimek (5 commits)")[![stevenmaguire](https://avatars.githubusercontent.com/u/1851973?v=4)](https://github.com/stevenmaguire "stevenmaguire (5 commits)")[![ViolanteCodes](https://avatars.githubusercontent.com/u/67020552?v=4)](https://github.com/ViolanteCodes "ViolanteCodes (4 commits)")[![martinalbert](https://avatars.githubusercontent.com/u/17796870?v=4)](https://github.com/martinalbert "martinalbert (4 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (2 commits)")[![zuzana-burianova](https://avatars.githubusercontent.com/u/99146730?v=4)](https://github.com/zuzana-burianova "zuzana-burianova (1 commits)")[![comanche](https://avatars.githubusercontent.com/u/1100167?v=4)](https://github.com/comanche "comanche (1 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)")

---

Tags

apiapi-clientcmslaravelphp

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3731.2M42](/packages/tencentcloud-tencentcloud-sdk-php)[convertkit/convertkitapi

Kit PHP SDK for the Kit API

2167.1k1](/packages/convertkit-convertkitapi)[mapado/rest-client-sdk

Rest Client SDK for hydra API

1125.9k2](/packages/mapado-rest-client-sdk)

PHPackages © 2026

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