CMS REST API: Retrieve Magento 2 CMS Pages & Block Data Using API

I am going to explain how we can load Magento 2 cms block content and cms page content on another website. By Using Wishusucess CMS REST API you can easily get the data to delete the data of your page and block.

Magento 2 CMS REST API

This module contains the only GET method but you can perform all kinds of getting operations over the cms page and cms block of your stores.

You can search page content by using the below route URL.

http://wishusucess.com/rest/all/V1/wishusucess/cmsPage/search

And for the block content search, you can use the below URL.

http://wishusucess.com/rest/all/V1/wishusucess/cmsBlock/search

For getting the whole cms page content we have to use below route URL of the cms page API

http://wishusucess.com/rest/store_id/V1/wishusucess/cmsPage/:pageId

The whole content of the block we can get by using below CMS Block REST API

http://wishusucess.com/rest/store_id/V1/wishusucess/cmsBlock/:blockId

 

Searching Using CMS REST API

We have also included the search content features using rest API on other websites. So you can easily call that API on any site and that will allow you to search the content of block and page.

You have to fill that search criterion to get the content of the block or page.

 

Available Endpoints Wishusucess_CMSApi

By using the following endpoint you can perform your desire action over the data on any website.

You just have to call the below endpoints:

http://wishusucess.com/rest/store_id/rest/V1/Wishusucess/cmsPage/:pageId

You can retrieves page information based on the page id

http://wishusucess.com/rest/store_id/rest/V1/Wishusucess/cmsPage/search

We can perform data retrieves operation on the list of pages.

http://wishusucess.com/rest/store_id/rest/V1/Wishusucess/cmsPageIdentifier/:identifier/storeId/:storeId

By giving integer value on page id we can get page content.

http://wishusucess.com/rest/store_id/rest/V1/Wishusucess/cmsBlock/:blockId

Can retrieve Magento 2 cms block data by giving block id.

http://wishusucess.com/rest/store_id/rest/V1/Wishusucess/cmsBlockIdentifier/:identifier/storeId/:storeId

Magento 2 cms block needs an identifier (string value) to get the block content using this REST API.

http://wishusucess.com/rest/store_id/rest/V1/Wishusucess/cmsBlock/search

Can get all the list of blocks on any website by using the above block rest API.

 

 

Step 1: Registration CMSApi

app/code/Wishusucess/CmsApi/registration.php

<?php
/**
*
* Developer: Hemant Singh Magento Certified Developer
* Category: Wishusucess_CmsApi
* Website: http://www.wishusucess.com/
*/
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Wishusucess_CmsApi',
__DIR__
);

 

Step 2: Basic Information About CMSApi

app/code/Wishusucess/CmsApi/etc/module.xml

<?xml version="1.0"?>
<!--
/**
*
* Developer: Hemant Singh Magento Certified Developer
* Category: Wishusucess_CmsApi
* Website: http://www.wishusucess.com/
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Wishusucess_CmsApi" setup_version="0.1.0">
</module>
</config>

 

Step 3: Dependency Injection of Module CMSApi

app/code/Wishusucess/CmsApi/etc/di.xml

<?xml version="1.0"?>
<!--
/**
*
* Developer: Hemant Singh Magento Certified Developer
* Category: Wishusucess_CmsApi
* Website: http://www.wishusucess.com/
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Wishusucess\CmsApi\Api\PageManagerInterface"
type="Wishusucess\CmsApi\Model\PageManager" />
<preference for="Wishusucess\CmsApi\Api\BlockManagerInterface"
type="Wishusucess\CmsApi\Model\BlockManager" />
<preference for="Wishusucess\CmsApi\Api\Data\BlockInterface"
type="Wishusucess\CmsApi\Model\Block" />
<preference for="Wishusucess\CmsApi\Api\Data\PageInterface"
type="Wishusucess\CmsApi\Model\Page" />
<preference for="Wishusucess\CmsApi\Api\Data\PageSearchResultsInterface"
type="Magento\Framework\Api\SearchResults" />
<preference for="Wishusucess\CmsApi\Api\Data\BlockSearchResultsInterface"
type="Magento\Framework\Api\SearchResults" />
<type name="Wishusucess\CmsApi\Model\BlockManager">
<arguments>
<argument name="collectionProcessor" xsi:type="object">Magento\Cms\Model\Api\SearchCriteria\BlockCollectionProcessor</argument>
</arguments>
</type>
<type name="Wishusucess\CmsApi\Model\PageManager">
<arguments>
<argument name="collectionProcessor" xsi:type="object">Magento\Cms\Model\Api\SearchCriteria\PageCollectionProcessor</argument>
</arguments>
</type>
</config>

 

Step 4: Route URL of CMS REST API

app/code/Wishusucess/CmsApi/etc/webapi.xml

<?xml version="1.0"?>
<!--
/**
*
* Developer: Hemant Singh Magento Certified Developer
* Category: Wishusucess_CmsApi
* 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/wishusucess/cmsPage/:pageId" method="GET">
<service class="Wishusucess\CmsApi\Api\PageManagerInterface" method="getById"/>
<resources>
<resource ref="Magento_Cms::page"/>
</resources>
</route>
<route url="/V1/wishusucess/cmsPageIdentifier/:identifier/storeId/:storeId" method="GET">
<service class="Wishusucess\CmsApi\Api\PageManagerInterface" method="getByIdentifier"/>
<resources>
<resource ref="Magento_Cms::page"/>
</resources>
</route>
<route url="/V1/wishusucess/cmsPage/search" method="GET">
<service class="Wishusucess\CmsApi\Api\PageManagerInterface" method="getList"/>
<resources>
<resource ref="Magento_Cms::page"/>
</resources>
</route>
<!-- Cms Block -->
<route url="/V1/wishusucess/cmsBlock/:blockId" method="GET">
<service class="Wishusucess\CmsApi\Api\BlockManagerInterface" method="getById"/>
<resources>
<resource ref="Magento_Cms::block"/>
</resources>
</route>
<route url="/V1/wishusucess/cmsBlockIdentifier/:identifier/storeId/:storeId" method="GET">
<service class="Wishusucess\CmsApi\Api\BlockManagerInterface" method="getByIdentifier"/>
<resources>
<resource ref="Magento_Cms::block"/>
</resources>
</route>
<route url="/V1/wishusucess/cmsBlock/search" method="GET">
<service class="Wishusucess\CmsApi\Api\BlockManagerInterface" method="getList"/>
<resources>
<resource ref="Magento_Cms::block"/>
</resources>
</route>
</routes>

 

Step 5: CMSApi Block Model

app/code/Wishusucess/CmsApi/Model/Block.php

<?php
/**
*
* Developer: Hemant Singh Magento Certified Developer
* Category: Wishusucess_CmsApi
* Website: http://www.wishusucess.com/
*/
namespace Wishusucess\CmsApi\Model;

use Wishusucess\CmsApi\Api\Data\BlockInterface;

class Block extends \Magento\Cms\Model\Block implements BlockInterface
{
/**
* @inheritdoc
*/
public function getStoreId()
{
return $this->_getData(self::STORE_ID);
}

/**
* @inheritdoc
*/
public function setStoreId(array $storeIds)
{
$this->setData(self::STORE_ID, $storeIds);

return $this;
}
}

 

Step 6: Model Class for Block Manager

app/code/Wishusucess/CmsApi/Model/BlockManager.php

<?php
/**
*
* Developer: Hemant Singh Magento Certified Developer
* Category: Wishusucess_CmsApi
* Website: http://www.wishusucess.com/
*/
namespace Wishusucess\CmsApi\Model;

use Magento\Cms\Api\BlockRepositoryInterface;
use Magento\Cms\Api\Data\BlockInterface;
use Magento\Cms\Model\BlockFactory;
use Magento\Cms\Model\ResourceModel\Block;
use Magento\Cms\Model\Template\FilterProvider;
use Magento\Framework\Api\DataObjectHelper;
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Store\Model\App\Emulation;
use Wishusucess\CmsApi\Api\BlockManagerInterface;
use Wishusucess\CmsApi\Api\Data\BlockInterfaceFactory;
use Wishusucess\CmsApi\Api\Data\BlockSearchResultsInterfaceFactory;
use Magento\Framework\App\State;
use Magento\Framework\App\Area;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class BlockManager extends ManagerBase implements BlockManagerInterface
{
/**
* @var BlockRepositoryInterface
*/
private $blockRepository;

/**
* @var FilterProvider
*/
private $filterProvider;

/**
* @var BlockFactory
*/
private $blockFactory;

/**
* @var Block
*/
private $blockResource;

/**
* @var BlockSearchResultsInterfaceFactory
*/
private $searchResultsFactory;

/**
* @var Block\CollectionFactory
*/
private $blockCollectionFactory;

/**
* @var CollectionProcessorInterface
*/
private $collectionProcessor;

/**
* @var BlockInterfaceFactory
*/
private $blockDtoFactory;

/**
* @var DataObjectHelper
*/
private $dataObjectHelper;

/**
* @var State
*/
private $appState;

/**
* @var Emulation
*/
private $emulation;

/**
* @param BlockRepositoryInterface $blockRepository
* @param FilterProvider $filterProvider
* @param BlockFactory $blockFactory
* @param Block $blockResource
* @param Block\CollectionFactory $blockCollectionFactory
* @param BlockSearchResultsInterfaceFactory $searchResultsFactory
* @param CollectionProcessorInterface $collectionProcessor
* @param BlockInterfaceFactory $blockDtoFactory
* @param DataObjectHelper $dataObjectHelper
* @param State $appState
* @param Emulation $emulation
*/
public function __construct(
BlockRepositoryInterface $blockRepository,
FilterProvider $filterProvider,
BlockFactory $blockFactory,
Block $blockResource,
Block\CollectionFactory $blockCollectionFactory,
BlockSearchResultsInterfaceFactory $searchResultsFactory,
CollectionProcessorInterface $collectionProcessor,
BlockInterfaceFactory $blockDtoFactory,
DataObjectHelper $dataObjectHelper,
State $appState,
Emulation $emulation
) {
$this->blockRepository = $blockRepository;
$this->filterProvider = $filterProvider;
$this->blockFactory = $blockFactory;
$this->blockResource = $blockResource;
$this->searchResultsFactory = $searchResultsFactory;
$this->blockCollectionFactory = $blockCollectionFactory;
$this->collectionProcessor = $collectionProcessor;
$this->blockDtoFactory = $blockDtoFactory;
$this->dataObjectHelper = $dataObjectHelper;
$this->appState = $appState;
$this->emulation = $emulation;
}

/**
* @inheritdoc
*/
public function getById($blockId)
{
$block = $this->blockRepository->getById($blockId);
$content = $this->getBlockContentFiltered($block->getContent());
$block->setContent($content);

return $block;
}

/**
* @inheritdoc
*/
public function getByIdentifier($identifier, $storeId = null)
{
$block = $this->blockFactory->create();
$block->setStoreId($storeId);
$this->blockResource->load($block, $identifier, BlockInterface::IDENTIFIER);

if (!$block->getId()) {
throw new NoSuchEntityException(
__('CMS Block with identifier "%1" does not exist.', $identifier)
);
}

$content = $this->getBlockContentFiltered($block->getContent());
$block->setContent($content);

return $block;
}

/**
* @inheritdoc
*/
public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
{
$storeId = $this->getStoreIdBySearchCriteria($searchCriteria);

if ($storeId !== null) {
$this->emulation->startEnvironmentEmulation($storeId);
}

/** @var \Magento\Cms\Model\ResourceModel\Block\Collection $collection */
$collection = $this->blockCollectionFactory->create();
$this->collectionProcessor->process($searchCriteria, $collection);

$items = [];
/** @var \Magento\Cms\Model\Block $block */
foreach ($collection->getItems() as $block) {
$content = $this->getBlockContentFiltered($block->getContent());
$block->setContent($content);
$blockDto = $this->blockDtoFactory->create();
$this->dataObjectHelper->populateWithArray(
$blockDto,
$block->getData(),
\Wishusucess\CmsApi\Api\Data\BlockInterface::class
);
$blockDto->setId($block->getId());
$items[] = $blockDto;
}

$searchResults = $this->searchResultsFactory->create();
$searchResults->setSearchCriteria($searchCriteria);
$searchResults->setItems($items);
$searchResults->setTotalCount(count($items));

if ($storeId !== null) {
$this->emulation->stopEnvironmentEmulation();
}

return $searchResults;
}

/**
* @param string $content
* @return string
*/
private function getBlockContentFiltered($content)
{
$emulatedResult = $this->appState->emulateAreaCode(
Area::AREA_FRONTEND,
[$this->filterProvider->getBlockFilter(), 'filter'],
[$content]
);

return $emulatedResult;
}
}

 

Step 7: CMSApi Model Manager for Search Criteria

app/code/Wishusucess/CmsApi/Model/ManagerBase.php

<?php
/**
*
* Developer: Hemant Singh Magento Certified Developer
* Category: Wishusucess_CmsApi
* Website: http://www.wishusucess.com/
*/
namespace Wishusucess\CmsApi\Model;

use Magento\Framework\Api\SearchCriteriaInterface;

class ManagerBase
{
/**
* @param SearchCriteriaInterface $searchCriteria
* @return int
*/
protected function getStoreIdBySearchCriteria(SearchCriteriaInterface $searchCriteria)
{
$filterGroups = $searchCriteria->getFilterGroups();

$storeIds = [];
foreach ($filterGroups as $filterGroup) {
foreach ($filterGroup->getFilters() as $filter) {
if ($filter->getField() == 'store_id') {
$storeIds = array_merge($storeIds, explode(',', $filter->getValue()));
}
}

if (count($storeIds) > 1) {
return 0; // default store
} else {
// if store_id wasn't passed as a filter,
// we should not continue with store emulation
return null;
}
}

return (int) array_shift($storeIds);
}
}

 

Step 8: CMS API For Page Model

app/code/Wishusucess/CmsApi/Model/Page.php

<?php
/**
*
* Developer: Hemant Singh Magento Certified Developer
* Category: Wishusucess_CmsApi
* Website: http://www.wishusucess.com/
*/
namespace Wishusucess\CmsApi\Model;

use Wishusucess\CmsApi\Api\Data\PageInterface;

class Page extends \Magento\Cms\Model\Page implements PageInterface
{
/**
* @inheritdoc
*/
public function getStoreId()
{
return $this->_getData(self::STORE_ID);
}

/**
* @inheritdoc
*/
public function setStoreId(array $storeIds)
{
$this->setData(self::STORE_ID, $storeIds);

return $this;
}
}

 

Step 9: Page Manager CMS REST API

app/code/Wishusucess/CmsApi/Model/PageManager.php

<?php
/**
*
* Developer: Hemant Singh Magento Certified Developer
* Category: Wishusucess_CmsApi
* Website: http://www.wishusucess.com/
*/
namespace Wishusucess\CmsApi\Model;

use Magento\Cms\Api\Data\PageInterface;
use Magento\Cms\Api\PageRepositoryInterface;
use Magento\Cms\Model\PageFactory;
use Magento\Cms\Model\ResourceModel\Page;
use Magento\Cms\Model\Template\FilterProvider;
use Magento\Framework\Api\DataObjectHelper;
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Store\Model\App\Emulation;
use Wishusucess\CmsApi\Api\Data\PageInterfaceFactory;
use Wishusucess\CmsApi\Api\Data\PageSearchResultsInterfaceFactory;
use Wishusucess\CmsApi\Api\PageManagerInterface;
use Magento\Framework\App\State;
use Magento\Framework\App\Area;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class PageManager extends ManagerBase implements PageManagerInterface
{
/**
* @var PageRepositoryInterface
*/
private $pageRepository;

/**
* @var FilterProvider
*/
private $filterProvider;

/**
* @var PageFactory
*/
private $pageFactory;

/**
* @var Page
*/
private $pageResource;

/**
* @var Page\CollectionFactory
*/
private $pageCollectionFactory;

/**
* @var PageSearchResultsInterfaceFactory
*/
private $searchResultsFactory;

/**
* @var CollectionProcessorInterface
*/
private $collectionProcessor;

/**
* @var PageInterfaceFactory
*/
private $pageDtoFactory;

/**
* @var DataObjectHelper
*/
private $dataObjectHelper;

/**
* @var State
*/
private $appState;

/**
* @var Emulation
*/
private $emulation;

/**
* @param PageRepositoryInterface $pageRepository
* @param FilterProvider $filterProvider
* @param PageFactory $pageFactory
* @param Page $pageResource
* @param Page\CollectionFactory $pageCollectionFactory
* @param PageSearchResultsInterfaceFactory $searchResultsFactory
* @param CollectionProcessorInterface $collectionProcessor
* @param PageInterfaceFactory $pageDtoFactory
* @param DataObjectHelper $dataObjectHelper
* @param State $appState
* @param Emulation $emulation
*/
public function __construct(
PageRepositoryInterface $pageRepository,
FilterProvider $filterProvider,
PageFactory $pageFactory,
Page $pageResource,
Page\CollectionFactory $pageCollectionFactory,
PageSearchResultsInterfaceFactory $searchResultsFactory,
CollectionProcessorInterface $collectionProcessor,
PageInterfaceFactory $pageDtoFactory,
DataObjectHelper $dataObjectHelper,
State $appState,
Emulation $emulation
) {
$this->pageRepository = $pageRepository;
$this->filterProvider = $filterProvider;
$this->pageFactory = $pageFactory;
$this->pageResource = $pageResource;
$this->pageCollectionFactory = $pageCollectionFactory;
$this->searchResultsFactory = $searchResultsFactory;
$this->collectionProcessor = $collectionProcessor;
$this->pageDtoFactory = $pageDtoFactory;
$this->dataObjectHelper = $dataObjectHelper;
$this->appState = $appState;
$this->emulation = $emulation;
}

/**
* @inheritdoc
*/
public function getById($pageId)
{
$page = $this->pageRepository->getById($pageId);
$content = $this->getPageContentFiltered($page->getContent());
$page->setContent($content);

return $page;
}

/**
* @inheritdoc
*/
public function getByIdentifier($identifier, $storeId = null)
{
$page = $this->pageFactory->create();
$page->setStoreId($storeId);
$this->pageResource->load($page, $identifier, PageInterface::IDENTIFIER);

if (!$page->getId()) {
throw new NoSuchEntityException(
__('CMS Page with identifier "%1" does not exist.', $identifier)
);
}

$content = $this->getPageContentFiltered($page->getContent());
$page->setContent($content);

return $page;
}

/**
* @inheritdoc
*/
public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
{
$storeId = $this->getStoreIdBySearchCriteria($searchCriteria);

if ($storeId !== null) {
$this->emulation->startEnvironmentEmulation($storeId);
}

/** @var \Magento\Cms\Model\ResourceModel\Page\Collection $collection */
$collection = $this->pageCollectionFactory->create();
$this->collectionProcessor->process($searchCriteria, $collection);

$items = [];
/** @var \Magento\Cms\Model\Page $page */
foreach ($collection->getItems() as $page) {
$content = $this->getPageContentFiltered($page->getContent());
$page->setContent($content);
$pageDto = $this->pageDtoFactory->create();
$this->dataObjectHelper->populateWithArray(
$pageDto,
$page->getData(),
\Wishusucess\CmsApi\Api\Data\PageInterface::class
);
$pageDto->setId($page->getId());
$items[] = $pageDto;
}

$searchResults = $this->searchResultsFactory->create();
$searchResults->setSearchCriteria($searchCriteria);
$searchResults->setItems($items);
$searchResults->setTotalCount(count($items));

if ($storeId !== null) {
$this->emulation->stopEnvironmentEmulation();
}

return $searchResults;
}

/**
* @param string $content
* @return string
*/
private function getPageContentFiltered($content)
{
$emulatedResult = $this->appState->emulateAreaCode(
Area::AREA_FRONTEND,
[$this->filterProvider->getPageFilter(), 'filter'],
[$content]
);

return $emulatedResult;
}
}

 

Step 10: Block Manager Class of CMSApi

app/code/Wishusucess/CmsApi/Api/BlockManagerInterface.php

<?php
/**
*
* Developer: Hemant Singh Magento Certified Developer
* Category: Wishusucess_CmsApi
* Website: http://www.wishusucess.com/
*/
namespace Wishusucess\CmsApi\Api;

interface BlockManagerInterface
{
/**
* @param int $blockId
* @return \Magento\Cms\Api\Data\BlockInterface
*/
public function getById($blockId);

/**
* @param string $identifier
* @param int $storeId
* @return \Magento\Cms\Api\Data\BlockInterface
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function getByIdentifier($identifier, $storeId = null);

/**
* @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
* @return \Wishusucess\CmsApi\Api\Data\BlockSearchResultsInterface
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria);
}

 

Step 11: Page Manager Interface

app/code/Wishusucess/CmsApi/Api/PageManagerInterface.php

<?php
/**
*
* Developer: Hemant Singh Magento Certified Developer
* Category: Wishusucess_CmsApi
* Website: http://www.wishusucess.com/
*/
namespace Wishusucess\CmsApi\Api;

interface PageManagerInterface
{
/**
* @param int $pageId
* @return \Magento\Cms\Api\Data\PageInterface
*/
public function getById($pageId);

/**
* @param string $identifier
* @param int $storeId
* @return \Magento\Cms\Api\Data\PageInterface
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function getByIdentifier($identifier, $storeId = null);

/**
* @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
* @return \Wishusucess\CmsApi\Api\Data\PageSearchResultsInterface
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria);
}

 

Step 12: Block Interface of API

app/code/Wishusucess/CmsApi/Api/Data/BlockInterface.php

<?php
/**
*
* Developer: Hemant Singh Magento Certified Developer
* Category: Wishusucess_CmsApi
* Website: http://www.wishusucess.com/
*/
namespace Wishusucess\CmsApi\Api\Data;

interface BlockInterface extends \Magento\Cms\Api\Data\BlockInterface
{
/**#@+
* Constants for keys of data array. Identical to the name of the getter in snake case
*/
const STORE_ID = 'store_id';
/**#@-*/

/**
* @return int[]
*/
public function getStoreId();

/**
* @param int[] $storeIds
* @return BlockInterface
*/
public function setStoreId(array $storeIds);
}

 

Step 13: Search Result Interface

app/code/Wishusucess/CmsApi/Api/Data/BlockSearchResultsInterface.php

<?php
/**
*
* Developer: Hemant Singh Magento Certified Developer
* Category: Wishusucess_CmsApi
* Website: http://www.wishusucess.com/
*/
namespace Wishusucess\CmsApi\Api\Data;

use Magento\Framework\Api\SearchResultsInterface;

interface BlockSearchResultsInterface extends SearchResultsInterface
{
/**
* @return \Wishusucess\CmsApi\Api\Data\BlockInterface[]
*/
public function getItems();

/**
* @param \Wishusucess\CmsApi\Api\Data\BlockInterface[] $items
* @return BlockSearchResultsInterface
*/
public function setItems(array $items);
}

 

Step 14: Get Page Store Id

app/code/Wishusucess/CmsApi/Api/Data/PageInterface.php

<?php
/**
*
* Developer: Hemant Singh Magento Certified Developer
* Category: Wishusucess_CmsApi
* Website: http://www.wishusucess.com/
*/
namespace Wishusucess\CmsApi\Api\Data;

interface PageInterface extends \Magento\Cms\Api\Data\PageInterface
{
/**#@+
* Constants for keys of data array. Identical to the name of the getter in snake case
*/
const STORE_ID = 'store_id';
/**#@-*/

/**
* @return int[]
*/
public function getStoreId();

/**
* @param int[] $storeIds
* @return BlockInterface
*/
public function setStoreId(array $storeIds);
}

 

Step 15: Page Search Result Interface

app/code/Wishusucess/CmsApi/Api/Data/PageSearchResultsInterface.php

<?php
/**
*
* Developer: Hemant Singh Magento Certified Developer
* Category: Wishusucess_CmsApi
* Website: http://www.wishusucess.com/
*/
namespace Wishusucess\CmsApi\Api\Data;

use Magento\Framework\Api\SearchResultsInterface;

interface PageSearchResultsInterface extends SearchResultsInterface
{
/**
* @return \Wishusucess\CmsApi\Api\Data\PageInterface[]
*/
public function getItems();

/**
* @param \Wishusucess\CmsApi\Api\Data\PageInterface[] $items
* @return PageSearchResultsInterface
*/
public function setItems(array $items);
}

 

Related Post:

Featured Product API: Get Featured Product Using Magento 2 REST API

How To Call Magento 2 REST API For Customer Account Update

How To GET Products List Using Magento 2 REST API

 

Recommended Post

Magento 2.4 Installation Guide: How to Install Magento 2.4.2

 

Download API