cancel
Showing results for 
Search instead for 
Did you mean: 

Get cmsBlock rest api having permission issue

SOLVED
Highlighted

Get cmsBlock rest api having permission issue

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 

2 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted

Re: Get cmsBlock rest api having permission issue

Hello @sidharth_kothar 

 

The following table lists the APIs that are no longer available to an anonymous user by default:

cms.PNG

 

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. 

Manish Mittal
https://www.manishmittal.com/

View solution in original post

Highlighted

Re: Get cmsBlock rest api having permission issue

@sidharth_kothar 

 

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.

Manish Mittal
https://www.manishmittal.com/

View solution in original post

5 REPLIES 5
Highlighted

Re: Get cmsBlock rest api having permission issue

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>

get_cms_block.png

 

Highlighted

Re: Get cmsBlock rest api having permission issue

Why we need admin token ?
I want to get these blocks from rest api and show on my page which any user can access

Highlighted

Re: Get cmsBlock rest api having permission issue

Hello @sidharth_kothar 

 

The following table lists the APIs that are no longer available to an anonymous user by default:

cms.PNG

 

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. 

Manish Mittal
https://www.manishmittal.com/

View solution in original post

Highlighted

Re: Get cmsBlock rest api having permission issue

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 ? 

Highlighted

Re: Get cmsBlock rest api having permission issue

@sidharth_kothar 

 

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.

Manish Mittal
https://www.manishmittal.com/

View solution in original post