Today, I am going to explain how you can load your Magento 2 website cms pages data on your other websites using CMS Page REST API.
By using default API to get Magento CMS Page content on the other website we can load all page data.
Magento 2 has an inbuilt rest API system. So we will use that default API, so then we do not need to create any files for the route URL and for the method.
<?xml version="1.0"?> <!-- /** * Developer: Hemant Singh Magento Certified Developer * Category: Wishusucess_CMSPage * Website: http://www.wishusucess.com/ */ --> <routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Webapi:etc/webapi.xsd"> <!-- Cms Page --> <route url="/V1/cmsPage/:pageId" method="GET"> <service class="Magento\Cms\Api\PageRepositoryInterface" method="getById"/> <resources> <resource ref="Magento_Cms::page"/> </resources> </route> </routes>
So at the end outcome of this article is to make you understand how you can get cms page content using REST API.
Step 1: Create Admin Access Token
Magento store verifies your authorization before giving you any response so if you will not authorize your request with an access token then the store will send you an error like you can't access the content because you are not an authorized user.
So, I have created an admin access token by using below admin REST API.
Payload: Admin Details (Admin User and Admin Password)
Now we have received an admin access token.
We will use that admin access token to authenticate our CMS API request.
So, in order to authenticate our request, we will add that admin token in the header content.
Step 2: CMS Page REST API Request
Now, I have sent a request to the Magento store by using the below Magento 2 CMS page API.
So our actual request with getting method looks like below url
Now with the above details send your CMS Page API request and your Magento store will send you a response with the content of that page.
Here in the screenshot, you can see we have received all the details like page identifier, page title, page id, page content, etc.
It's very useful when we get access of our Magento 2 Page content and load on other website without any extra effort of coding or development of Magento CMS API.