Your action name should be
$action = 'syncreports_sync.info';
In general here is how an API v1 method name should look.
entity_alias.method
| |
| |------------the name of the method to call.Child of the `<methods>` tag in the `api.xml` file
|
|--- the tag name you specified in `api.xml` inside the `<resources>` tag
[EDIT]
Your other issue is caused by the fact that you are missing the model declarations in config.xml
.
Add this inside the <global>
tag
<models>
<syncreports>
<class>Mycompany_Syncreports_Model</class>
</syncreports>
</models>
If you want to use mycompany_syncreports
as a model alias just like you do for helpers put this xml instead of the above
<models>
<mycompany_syncreports>
<class>Mycompany_Syncreports_Model</class>
</mycompany_syncreports>
</models>
But in this case you need to modify your api.xml
.
Change this line:
<model>syncreports/sync_api</model>
To this one
<model>mycompany_syncreports/sync_api</model>
Magento2 supports two formats of the messages for REST APIs: json and xml. Let's take json as an example: the api call for the service you created will looks like this:
curl -X POST "http://magento.url/rest/V1/vakri/update" -H "Content-Type: application/json" -d '{"xml": "<OrderEventNotification Id="E201602261456522075"> .. "}'
As you see here, you should have field, "xml", which corresponds to input parameter name of the method.
For XML it might be a bit more tricky, I would assume something like
curl -X POST "http://magento.url/rest/V1/vakri/update" -H "Content-Type: application/xml" -d '<xml>"<OrderEventNotification Id="E201602261456522075"> .. "</xml>'
In any case, there will be a problem if xml code contains characters which can break the request json/xml structure. One way to overcome that is to obfuscate xml string with some encoding, let's say base64, or escape all dangerous characters. In API service implementation you would need to do reverse operation.
Another, and much better way, is to actually create the Data Object, which represents the data from the XML file. Instead of sending raw XML string, you'll just use possibilities of Web API framework to serialize/deserialize data.
namespace Ezprints\Valkyrie\Model\Api\Data;
interface OrderEventNotificationInterface
{
/**
* @return string
*/
public function getId();
/**
* @return string
*/
public function getOrderId();
/**
* @return string
*/
public function getEZPReferenceNumber();
/**
* @return string
*/
public function getAcceptedDateTime();
}
namespace Ezprints\Valkyrie\Model\Api;
interface ValkyrieStatusUpdateInterface
{
/**
* Parse the notification XML and handle accordingly
*
* @api
* @param Data\OrderEventNotificationInterface $orderNotification
* @return Data\OrderEventNotificationResponseInterface
*/
public function processVaklyrieStatusUpdate(Data\OrderEventNotificationInterface $orderNotification);
}
API call will looks like:
curl -X POST "http://magento.url/rest/V1/vakri/update" -H "Content-Type: application/xml" -d '<id>E201602261456522075</id><order_id> 000000024</order_id><e_z_p_reference_number>0-01-7899-201602242228-0027-3808</e_z_p_reference_number><accepted_date_time>2016-02-26T21:27:55<accepted_date_time>'
Best Answer
You don't need to create adapters and handlers. IN the article Alan wrote he explains how the handlers and adapters work. But they are already there. Of course if you want to add a new type of service you may need a handler but Magento already has SOAP and REST. What more do you want? :).
Here is a small example on how you can extend the existing API
Here is a big example on how you can add the files needed for the API in your custom module.
I can also recommend you this extension. It will build you a module with the SOAP API files included. It could be a good place to start learning how it works.
Build a module with it with the API included and one without the API then see what are the differences. that will tell you what files you need to create for the API.