microcmsio / microcms-php-sdk
microCMS PHP SDK
Installs: 41 792
Dependents: 0
Suggesters: 0
Security: 0
Stars: 18
Watchers: 6
Forks: 1
Open Issues: 0
Requires
- ext-json: *
- guzzlehttp/guzzle: ^7.0
Requires (Dev)
- phpstan/phpstan: ^0.12.99
- phpunit/phpunit: ^9.5
- psy/psysh: @stable
README
microCMS PHP SDK.
Tutorial
See official tutorial.
Installation
$ composer require microcmsio/microcms-php-sdk
Usage
Import
<?php require_once('vendor/autoload.php'); use \Microcms\Client;
Create client object
$client = new Client( "YOUR_DOMAIN", // YOUR_DOMAIN is the XXXX part of XXXX.microcms.io "YOUR_API_KEY" // API Key );
Get content list
$list = $client->list("endpoint"); echo $list->contents[0]->title;
Get content list with parameters
$list = $client->list("endpoint", [ "draftKey" => "foo", "limit" => 10, "offset" => 1, "orders" => ["createdAt", "-updatedAt"], "q" => "PHP", "fields" => ["id", "title"], "filters" => "title[contains]microCMS", "depth" => 1 ]); echo $list->contents[0]->title;
Get single content
$object = $client->get("endpoint", "my-content-id"); echo $object->title;
Get single content with parameters
$object = $client->get("endpoint", "my-content-id", [ "draftKey" => "foo", "fields" => ["id", "title"], "depth" => 1, ]); echo $object->title;
Get object form content
$object = $client->get("endpoint"); echo $object->title;
Create content
$createResult = $client->create( "endpoint", [ "title" => "Hello, microCMS!", "contents" => "Awesome contents..." ] ); echo $createResult->id;
Create content with specified ID
$createResult = $client->create( "endpoint", [ "id" => "new-my-content-id", "title" => "Hello, microCMS!", "contents" => "Awesome contents..." ] ); echo $createResult->id;
Create draft content
$createResult = $client->create( "endpoint", [ "title" => "Hello, microCMS!", "contents" => "Awesome contents..." ], [ "status" => "draft" ] ); echo $createResult->id;
Update content
$updateResult = $client->update("endpoint", [ "id" => "new-my-content-id", "title" => "Hello, microCMS PHP SDK!" ]); echo $updateResult->id;
Update object form content
$updateResult = $client->update("endpoint", [ "title" => "Hello, microCMS PHP SDK!" ]); echo $updateResult->id;
Delete content
$client->delete("endpoint", "new-my-content-id");