Getting Started
This document outlines the shortest steps to use microCMS from a PHP application.
If you are using microCMS from a PHP application for the first time, please try these steps first.
Prerequisites
- You will need PHP and Composer. Please install them in your development environment.
- You must have completed the creation of the microCMS service. If you haven't done this, please refer to the document below.
In the API creation screen, enter the desired API name and endpoint.

Next, select the object format.

Finally, set the fields. This time, we will set only one text field.

With the above settings, the API will be created, allowing you to submit content.
Move to the editing screen, enter the desired values, and publish.

At this point, a response containing content data will be returned from the API.
Click on the API preview in the upper right corner to access the created API and confirm that a JSON response is being returned.

Fetching Data with PHP
First, create a composer.json file and install the microcms-php-sdk.
$ composer init --no-interaction --name "test/test" --description "test"
$ composer require microcmsio/microcms-php-sdkNext, create the src/Main.php file.
$ mkdir src
$ touch src/Main.phpHere, we will write the code to fetch data from the microCMS API.
<?php
require_once('vendor/autoload.php');
$client = new \Microcms\Client(
"service-domain",
"api-key"
);
echo $client->get("hello")->text;The service-domain and api-key are different for each service, so you need to configure them according to the respective service.
Set the service-domain to the XXXX part of the service you created at "https://XXXX.microcms.io". For the api-key, copy and paste the string of the automatically generated API key. Select "1 API key" at the bottom of the sidebar to navigate to the API key list, and copy and paste the existing API key.
After that, let's run Main.php. You will be able to fetch the content submitted to microCMS.
$ php ./src/Main.php
Hello, microCMS!