Magento – Request does not match any route issue in magento 2

magento2rest apiwebapi

I have creating a extension for get cms static block content using rest api.

di.xml

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

webapi.xml

    <?xml version="1.0"?>
<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/snowdog/cmsPage/:pageId" method="GET">
        <service class="Snowdog\CmsApi\Api\PageManagerInterface" method="getById"/>
        <resources>
            <resource ref="Magento_Cms::page"/>
        </resources>
    </route>
    <route url="/V1/snowdog/cmsPageIdentifier/:identifier/storeId/:storeId" method="GET">
        <service class="Snowdog\CmsApi\Api\PageManagerInterface" method="getByIdentifier"/>
        <resources>
            <resource ref="Magento_Cms::page"/>
        </resources>
    </route>
    <route url="/V1/snowdog/cmsPage/search" method="GET">
        <service class="Snowdog\CmsApi\Api\PageManagerInterface" method="getList"/>
        <resources>
            <resource ref="Magento_Cms::page"/>
        </resources>
    </route>
    <!-- Cms Block -->
    <route url="/V1/snowdog/cmsBlock/:blockId" method="GET">
        <service class="Snowdog\CmsApi\Api\BlockManagerInterface" method="getById"/>
        <resources>
            <resource ref="Magento_Cms::block"/>
        </resources>
    </route>
    <route url="/V1/snowdog/cmsBlockIdentifier/:identifier/storeId/:storeId" method="GET">
        <service class="Snowdog\CmsApi\Api\BlockManagerInterface" method="getByIdentifier"/>
        <resources>
            <resource ref="anonymous"/>
        </resources>
    </route>
    <route url="/V1/snowdog/cmsBlock/search" method="GET">
        <service class="Snowdog\CmsApi\Api\BlockManagerInterface" method="getList"/>
        <resources>
            <resource ref="Magento_Cms::block"/>
        </resources>
    </route>
</routes>
  1. passing url

http://vaibhav.local/rest/V1/snowdog/cmsBlock?29

  1. getting error

When I am hit URL I got Request does not match any route. issue.

Can anyone help me to solve this.

Thanks In advance..!

Best Answer

Your endpoint should be:

rest/V1/snowdog/cmsBlock/29

instead of

rest/V1/snowdog/V1/snowdog/cmsBlock?29

UPDATE: it should be routes not route.

<?xml version="1.0"?>
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Webapi:etc/webapi.xsd">
    <route url="/V1/snowdog/cmsBlock/:blockId" method="GET">
        <service class="Snowdog\CmsApi\Api\BlockManagerInterface" method="getById"/>
        <resources>
            <resource ref="Magento_Cms::block"/>
        </resources>
    </route>
</routes>
Related Topic