I am tring to get a cmsblock by rest api like https://XXX.ent.magento.cloud/rest/all/V1/cmsBlock/10
where 10 is block id
But I am getting auth 401 error
I have tried to pass auth header but that also not working
Solved! Go to Solution.
Hello @sidharth_kothar
The following table lists the APIs that are no longer available to an anonymous user by default:
For more reference:
https://devdocs.magento.com/guides/v2.3/rest/anonymous-api-security.html
You can use customer token as well instead admin token for security purpose.
You can override below shared file and change
vendor/magento/module-cms/etc/webapi.xml
<route url="/V1/cmsBlock/:blockId" method="GET"> <service class="Magento\Cms\Api\BlockRepositoryInterface" method="getById"/> <resources> <resource ref="Magento_Cms::block"/> </resources> </route>
to
<route url="/V1/cmsBlock/:blockId" method="GET"> <service class="Magento\Cms\Api\BlockRepositoryInterface" method="getById"/> <resources> <resource ref="anonymous"/> </resources> </route>
Clear cache bin/magento c:f
You can access now it as anonymous.
Hi @sidharth_kothar
Use this API to get CMS block content:
url: http://<base_url>rest/V1/cmsBlock/1 example: http://localhost/MagentoCE-2-3-2/rest/V1/cmsBlock/1
Method : GET
Content-Type:application/json
Authorization:Bearer <admin-token>
Why we need admin token ?
I want to get these blocks from rest api and show on my page which any user can access
Hello @sidharth_kothar
The following table lists the APIs that are no longer available to an anonymous user by default:
For more reference:
https://devdocs.magento.com/guides/v2.3/rest/anonymous-api-security.html
You can use customer token as well instead admin token for security purpose.
I have tried with customer token but that didn't worked .
Also I need to have this enable for anonymous user so guest user can also see these blocks
any way to enable this for anonymous users ?
You can override below shared file and change
vendor/magento/module-cms/etc/webapi.xml
<route url="/V1/cmsBlock/:blockId" method="GET"> <service class="Magento\Cms\Api\BlockRepositoryInterface" method="getById"/> <resources> <resource ref="Magento_Cms::block"/> </resources> </route>
to
<route url="/V1/cmsBlock/:blockId" method="GET"> <service class="Magento\Cms\Api\BlockRepositoryInterface" method="getById"/> <resources> <resource ref="anonymous"/> </resources> </route>
Clear cache bin/magento c:f
You can access now it as anonymous.