I'm trying to create an api route with input parameters but I'm not getting the expected result.
Here is my webapi.xml:
<?xml version="1.0"?>
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../app/code/Magento/Webapi/etc/webapi.xsd">
<route url="/V1/foo" method="POST" secure="true">
<service class="..\FooInterface"
method="getFooById"/>
<resources>
<resource ref="anonymous"/>
</resources>
<data>
<parameter name="id" force="true">%id%</parameter>
</data>
</route>
</routes>
Here my interface:
interface FooInterface
{
/**
* Test function
*
* @api
* @param string $id
* @return string
*/
public function getFooById($id);
}
And here the class:
class Foo implements FooInterface
{
/**
* {@inheritdoc}
*/
public function getFooById($id){
return $id;
}
}
I'm omitting the di.xml with the preference.
Now if I call that route whatever I do all I get back is %id%
. Even if I don't put any parameter I get that instead of an error or something.
What am I doing wrong here?
I tried:
- sending a get request
- sending a get request with parameter
/order?id=foo
- sending a post request
- sending a post request with form-data
- sending a post request with raw data (as seen in screenshot)
All have the same result -> %id%