Skip to content

Magento 2 – Rest API error – The consumer isn’t authorized to access %resources

I am following the document to create a Rest API:
https://developer.adobe.com/commerce/php/tutorials/backend/create-custom-rest-api/

and defined user roles:

enter image description here
enter image description here
enter image description here

Generate Admin Access Token:
enter image description here

If i try with the following API, i am getting an error:
http://magento2.local/rest/V1/rest_dev/getProduct/1

Postman:
enter image description here

What is the error? I created admin access token and passed right, why i am getting this error?

Folder Structure:
enter image description here

/var/www/html/magento2/app/code/Dev/RestApi/etc/acl.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
    <acl>
        <resources>
            <resource id="Magento_Backend::admin">
                <resource id="Dev_RestApi::products" title="Dev API - Products"
                          translate="title" sortOrder="110">
                    <resource id="Dev_RestApi::products_get" title="Get product"
                              translate="title" sortOrder="10" />
                    <resource id="Dev_RestApi::products_set_description" title="Set description"
                              translate="title" sortOrder="20" />
                </resource>
            </resource>
        </resources>
    </acl>
</config>

Environment : WSL on Windows.