You can create custom module and post data to controller action from mobile app.
Controller File Name : SearchListing.php
<?php
// you can trigger the controller action from app posting search term to it
// api url will be : http://domain/front_name/controller_name/action_name
// lets consider in our case url will be http://example.com/api/searchlisting
namespace NameSpace\Modulename\Controller;
use Magento\Framework\App\Action\Context;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
use NameSpace\Modulename\Helper\Data as CustomerAPIHelper;
class SearchListing extends \NameSpace\Modulename\Controller\Authentication\Magento\Framework\App\Action\Action
{
/**
* @var Magento\Store\Model\StoreManagerInterface
*/
protected $_storeManagerInterface;
/**
* @var CustomApiHelper
*/
protected $_customApiHelper;
protected $_productCollectionFactory;
/**
* @param Context $context
* @param Category $_category
* @param PageFactory $resultPageFactory
* @param StoreManagerInterface $storeManagerInterface
*/
public function __construct(
Context $context,
StoreManagerInterface $storeManagerInterface,
CollectionFactory $productCollectionFactory,
CustomerAPIHelper $customapihelper
) {
$this->_productCollectionFactory = $productCollectionFactory;
$this->_storeManagerInterface = $storeManagerInterface;
$this->_customApiHelper = $customapihelper;
parent::__construct($context);
}
public function execute()
{
try{
$request = $this->_request->getParams();
if(!empty($request))
{
// get the search term submitted from mobile app
$search_term = $request["search_term"];
$temp = array();
$productCollectionData = array();
$fieldsToSelect = array('name', 'short_description','price','image');
// Call to ThirdParty Module to which you will pass $search_term
$response = $this->ThirdPartyFunctionAcceptingSearchTermAsParameter($search_term);
echo json_encode(array('status' => true,'data' => $response));
} else {
echo json_encode(array('status' => false,'message' => "Search Term missing"));
exit;
}
} catch(Exception $e) {
echo json_encode(array('status' => false,'message' => $e->getMessage()));
exit;
}
}
}
etc/frontend/routes.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/App/etc/routes.xsd">
<router id="standard">
<route id="api" frontName="api">
<module name="NameSpace_ModuleName" />
</route>
</router>
</config>