

Let’s implement the last part – the class that actually does something 😉 To be clear, they don’t have to extend DataObject, it was just easier (and quicker) for me to implement it this way. They extend DataObject and implement getters and setters. Return $this->setData(self::DATA_NAME, $name) Return $this->setData(self::DATA_SKU, $sku) Return $this->setData(self::DATA_DESCRIPTION, $description) Public function setDescription(string $description) Return $this->setData(self::DATA_ID, $id) Return $this->_getData(self::DATA_DESCRIPTION) There is one more interface left to create. getSkuPrefix(), setSkuPrefix(string $skuPrefix) \Magently\RestApi\Api\ProductRepositoryInterface – this will be our entry point for all of the endpoints. It allows Magento to correctly map JSON/XML data to objects and the other way around. Basically, and in PHPDoc have to be very specific. There are a few rules you have to follow when creating the interfaces. If you want to make it public (no authentication), you can use: Interfaces

Resource sets the ACL resource that is required to have access to the endpoint. Service informs about the interface and the method to be called when the endpoint is reached. You should follow the rules of the REST API specification:īoth URL and method have to match in the request.

Make sure the URL you want to use isn’t already in use (in combination with the same method). Magento requires this value to start with a slash, “V” and an integer number, which should inform about our API version. If you skip the store code, the default store will be used.
#Magento 2 devdocs acl full
Route.url is a URL of the endpoint, the full address would be: /rest/ Next – define the endpoints in app/code/Magently/RestApi/etc/webapi.xml We defined one main record and three child records – one for each endpoint, to have full control over who can access what. Implementation Moduleįirstly, let’s start by creating a new module.Īpp/code/Magently/RestApi/etc/module.xml : Īpp/code/Magently/RestApi/registration.php : Our module will be called Magently_RestApi. I used Magento 2.3.5 with sample data in this example, but – as far as I know – everything should work the same on every 2.x version. Thus, let’s create custom custom API endpoint in Magento. But access to these endpoints would mean access to all of the data, not just the description. Magento already has API endpoints to get and modify product data. Let’s assume a store owner wants to outsource managing product descriptions to some company.
