Magento 2 API – Get CMS Page Content
End-to-end Magento integration
Integrate any app or service. Consult our API development experts.
Hello Magento Peeps!
Welcome to Meetanshi’s Magento 2 API – Get CMS Page Content tutorial. This post is part of our Magento 2 API series. In case you are a budding developer, do check out our other Magento 2 API tutorials.
So, let’s begin with Magento 2 API – Get CMS Page Content!
If you are developing a mobile shopping app on Magento 2, you may require to fetch the CMS pages and block to show it to the customers. Not to forget that Magento 2 is a robust eCommerce platform that provides plenty of powerful APIs to harness the full potential of the platform. In this blog post, I will be showing you how to get CMS page content using Magento 2 APIs.
How to Get CMS Page & Block Content Using Magento 2 API?
In order to get the CMS page and block content in Magento 2 through APIs, we need to perform a GET call to the respective path with the path KEY and variable ID. Let’s understand it in a more better way using examples.
Get CMS Page in Magento 2
We’ll be sending a GET request to store_url/cmsPage/:aboutCmsid with the required page id to get CMS page in Magento 2. Refer to the example provided below for more details.
Method: GET
URL: store_url/cmsPage/:aboutCmsid
Path Variables
- VALUE: aboutCmsid
- KEY: 5
Response: The response returns the required page.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
{ "id": 5, "identifier": "about-us", "title": "About us", "page_layout": "1column", "meta_keywords": "", "meta_description": "", "content_heading": "About us", "content": "<div class="about-info cms-content">n <p class="cms-content-important">With more than 230 stores spanning 43 states and growing, Luma is a nationally recognized active wear manufacturer and retailer. We’re passionate about active lifestyles – and it goes way beyond apparel.</p>nn <p>At Luma, wellness is a way of life. We don’t believe age, gender or past actions define you, only your ambition and desire for wholeness... today.</p>nn <p>We differentiate ourselves through a combination of unique designs and styles merged with unequaled standards of quality and authenticity. Our founders have deep roots in yoga and health communities and our selections serve amateur practitioners and professional athletes alike.</p>nn <ul style="list-style: none; margin-top: 20px; padding: 0;">n <li><a href="{{store url="contact"}}">Contact Luma</a></li>n <li><a href="{{store url="customer-service"}}">Customer Service</a></li>n <li><a href="{{store url="privacy-policy"}}">Luma Privacy Policy</a></li>n <li><a href="{{store url=""}}">Shop Luma</a></li>n </ul>n </div>n", "creation_time": "2020-11-30 12:49:33", "update_time": "2020-11-30 12:49:33", "sort_order": "0", "layout_update_xml": "", "custom_theme": "", "custom_root_template": "", "active": true } |
That’s it! This is how you can get the cms page in Magento 2 through API.
Get CMS Block in Magento 2
In order to get the CMS block in Magento 2 through API, the client needs to send a GET request to the store_url/cmsBlock/ and pass the variables in the parameters. Refer to the following example for more understanding.
Method: GET
URL: store_url/cmsBlock/:homeCmsid
Path Variables
- KEY: homeCmsid
- VALUE: 9
Response:
The request will return the required page details in the following format:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
{ "id": 9, "identifier": "training-block", "title": "Training Block", "content": "<div class="blocks-promo">nn <a href="{{store url=""}}training.html" class="block-promo training-main">n <img src="{{media url="wysiwyg/training/training-main.jpg"}}" alt="" />n <span class="content">n <strong class="title">n <span>Motivate</span> yourself.<br />n <span>Reach</span> goals.<br />n <span>Boost</span> ambition.<br />n <span>Max</span> fitness.<br />n <span>Upgrade</span> lifestyle.n </strong>n </span>n </a>n <a href="{{store url=""}}collections/erin-recommends.html" class="block-promo training-erin">n <img src="{{media url="wysiwyg/training/training-erin.jpg"}}" alt="" />n <span class="content">n <strong class="title">Before creating Luma, pro trainer Erin Renny helped world-class athletes reach peak fitness</strong>n <span class="info">Hand-selected by Erin, our training downloads reflect a commitment to yoga, health and wellness.</span>n </span>n </a>n <a href="{{store url=""}}training/training-video.html" class="block-promo training-on-demand">n <span class="content">n <span class="icon download"><span>Download</span></span>n <strong class="title">Training on demand</strong>n <span class="info">Luma downloads to inspire and challenge.<br />Your space, your pace</span>n <span class="more icon">Videos</span>n </span>n </a>n</div>n<div class="content-heading">n <h2 class="title">Top Videos</h2>n <p class="info">Stream free with subscription</p>n</div>n{{widget type="Magento\CatalogWidget\Block\Product\ProductsList" products_count="4" template="product/widget/content/grid.phtml" conditions_encoded="^[`1`:^[`type`:`Magento||CatalogWidget||Model||Rule||Condition||Combine`,`aggregator`:`all`,`value`:`1`,`new_child`:``^],`1--1`:^[`type`:`Magento||CatalogWidget||Model||Rule||Condition||Product`,`attribute`:`sku`,`operator`:`()`,`value`:`241-MB08, 240-LV05, 240-LV09, 240-LV07`^]^]"}}", "creation_time": "2020-11-30 12:49:33", "update_time": "2020-11-30 12:49:33", "active": true } |
That’s it!
This is how you can get the CMS page and block in Magento 2 through APIs.
Conclusion
Magento 2 API is useful while developing another applications based on the platform. Magento 2 API CMS page & block content is useful to show the contents of the website on other applications. I hope this blog post will help you through the same.😊
In case you still have any queries or doubts regarding the solution provided, feel free to comment. I would be happy to help you.😇
Thanks for reading.🍀
Jignesh Parmar
An expert in his field, Jignesh is the team leader at Meetanshi and a certified Magento developer. His passion for Magento has inspired others in the team too. Apart from work, he is a cricket lover.
Prev
How To Use Custom Option Image in Magento 2 to Boost Sales
Magento 2 API – Get All Categories
Next