2

Error is "message": "Internal Error. Details are available in Magento log file. Report ID: webapi-5dee36e254394".

When you run http://localhost:8888/magento/rest/V1/position/1

Need to get result from "position" column.

Api is for retrieving a column field by given user input.

<?php
 namespace SimpleMagento\Custom\Model;

use SimpleMagento\Custom\Api\InfoLinkInterface;
use SimpleMagento\Custom\Model\ResourceModel\Info\CollectionFactory; //Collection file
use SimpleMagento\Custom\Model\InfoFactory; //Implemented getter setter model

class InfoLink implements InfoLinkInterface
{
   private $collection;
   private $infoFactory;
   public function __construct(CollectionFactory $collection,InfoFactory $infoFactory)
{
    $this->collection=$collection;
    $this->infoFactory=$infoFactory;
} 
/**
 * @param int $id
 * @return \SimpleMagento\Custom\Api\Data\InfoInterface[]
 */

public function getInfo($id)
{

    return $this->infoFactory->create()->getCollection()->addFieldToFilter('entity_id',$id)->getData();
    //return $this->infoFactory->create()->getData('position')->addFieldToFilter('entity_id',1);

}
 }

?>

webapi.xml is

<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Webapi:etc/webapi.xsd">

<route url="/V1/position/:id" method="GET">
    <service class="SimpleMagento\Custom\Api\InfoLinkInterface" method="getInfo"/>
    <resources>
        <resource ref="anonymous" />
    </resources>
</route>

3
  • Can you please add here var/report/api or exception.log ? Commented Dec 9, 2019 at 13:02
  • 2019-12-09 12:57:41] main.CRITICAL: Report ID: webapi-5dee44c52bdb3; Message: Class SimpleMganeto\Custom\Model\InfoLink does not exist {"exception":"[object] (Exception(code: -1): Report ID: webapi-5dee44c52bdb3; Message: Class SimpleMganeto\\Custom\\Model\\InfoLink does not exist at /Applications/MAMP/htdocs/magento/vendor/magento/framework/Webapi/ErrorProcessor.php:205, ReflectionException(code: -1): Class SimpleMganeto\\Custom\\Model\\InfoLink does not exist at /Applications/MAMP/htdocs/magento/vendor/magento/framework/Code/Reader/ClassReader.php:19)"} [] Commented Dec 9, 2019 at 13:11
  • Make sure flush cache after change in di.xml file. Commented Dec 9, 2019 at 13:16

2 Answers 2

0

It seems like you added wrong model file class name in your di.xml file :

Change from :

SimpleMganeto\Custom\Model\InfoLink

To :

SimpleMagento\Custom\Model\InfoLink

6
  • Thanks a lot for correction but not able to get, even after that. Code flow of developing API is corect, right? . To make it more simple I ll write SQL query , from which is I want to get result. **SELECT POISITION FROM NEW INFO WHERE ENTITY_ID=$ID ** Commented Dec 10, 2019 at 4:10
  • You added addFieldToFilter with entity_id. I think it should be position. Commented Dec 10, 2019 at 4:23
  • what you get data in getInfo function? Commented Dec 10, 2019 at 4:24
  • just a string from position column Commented Dec 10, 2019 at 4:27
  • If there will be unique record in your table. Then, you can use $record = $this->infoFactory->create()->getCollection()->addFieldToFilter('entity_id',$id)->getLastItem(); ................ and then you can return, $record->getPosition(); or $record['position']; Commented Dec 10, 2019 at 4:30
0

Try to replace this line

return $this->infoFactory->create()->getCollection()->addFieldToFilter('entity_id',$id)->getData();

With this one

return $this->infoFactory->create()->getCollection()->addFieldToFilter('entity_id',array('eq', $id))->getFirstItem()->getPosition();

Follow this link for reference.

Hope this will help you!

6
  • Let me know if you need any help then. ;) Commented Dec 10, 2019 at 7:30
  • we just need to add ** localhost:8888/magento/rest/V1/position/1 ** This in postman right? So that :id=1 Commented Dec 10, 2019 at 8:03
  • Yes, @AkashKilledar. Right Commented Dec 10, 2019 at 8:38
  • but error in postman is "message": "Server internal error. See details in report api/617778416808" :- 'Uncaught Error: Cannot instantiate interface. Commented Dec 10, 2019 at 9:08
  • Can you please send me full error ? Commented Dec 10, 2019 at 9:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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