1

I'm building rest API to get a product using its sku, but it give me this message "Request doesn't match any route" although the url in webapi.xml file is the same in the request. magento version is 2.1.15

here is module.xml -

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">

   <module name="Bit68_Mobileapp" setup_version="2.1.15"/>

</config>

here is 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="\Bit68\Mobileapp\Api\Product\ProductInterface" type="\Bit68\Mobileapp\Model\Product\Product"/>
</config>

here is the webapi.xml -

<?xml version="1.0"?>

<route url="/V1/status" method="GET">
    <service class="\Bit68\Mobileapp\Api\Product\ProductInterface" method="getStatus"/>
    <resources>
        <resource ref="anonymous"/>
    </resources>
</route>

here is the interface -

<?php

namespace Bit68\Mobileapp\Api\Product;

 interface ProductInterface{
/**
 * get test Api data.
 *
 * @api
 *
 * @return string
 */
public function getStatus();}?>

and that is the implementation for the interface

<?php

namespace Bit68\Mobileapp\Model\Product;

use Bit68\Mobileapp\Api\Product\ProductInterface;

class Product implements ProductInterface{
/**
* @var \Magento\Catalog\Model\ProductRepository
*/
private $productRepository; 


/**
* @param \Magento\Catalog\Api\ProductRepositoryInterface
*/
public function __construct(

    \Magento\Catalog\Api\ProductRepositoryInterface $productRepository

) {
    $this->productRepository = $productRepository;
}


/**
* get test Api data.
*
* @api
*
* @return string
*/

function getStatus()
{
    //echo "helllloooo";
    $product=$this->$productRepository->get('pro');

    return "found";
}


}

?>

my request is http://127.0.0.1/yourParts/rest/V1/status/Authorization:Bearer_TOKEN

1

You are sending token in URL whereas your URL should be like V1/status. Send bearer token in header instead of URL Authorization: Bearer TOKEN.

And I think as this is anonymous api so you don't need to send token in this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.