Important
You are browsing the documentation for version 4.1 of OroCommerce, OroCRM and OroPlatform, which is no longer maintained. Read version 5.1 (the latest LTS version) of the Oro documentation to get up-to-date information.
See our Release Process documentation for more information on the currently supported and upcoming releases.
Storefront REST API¶
The REST API resources for the storefront are accessible via http://<hostname>/api,
while REST API resources for the back-office is accessible via http://<hostname>/admin/api.
There are also two REST API sandboxes, one for the storefront (http://<hostname>/api/doc) and another
for the back-office (http://<hostname>/admin/api/doc).
Note
Please note that the admin prefix is used by default and can be changed via the web_backend_prefix parameter.
All approaches described in API Developer Guide are applicable to REST API resources for the storefront but there are several differences:
for configuration files use
Resources/config/oro/api_frontend.yml, notResources/config/oro/api.ymlthe default value for
exclusion_policyoption iscustom_fields, it means that all custom fields (fields withis_extend=trueandowner=Custominextendscope in entity configuration) that are not configured explicitly are excludedfor documentation files use
Resources/doc/api_frontendfolder, notResources/doc/apifor API processors use
frontendrequest typefor API routes use
Oro\Bundle\FrontendBundle\Controller\FrontendRestApiControllercontroller instead ofOro\Bundle\ApiBundle\Controller\RestApiController,frontend_rest_apigroup instead ofrest_apiand setfrontendoption totruefor CORS requests configuration use
oro_frontend / frontend_api / corssection, notoro_api / corsfor API functional tests use
Oro\Bundle\FrontendBundle\Tests\Functional\Api\FrontendRestJsonApiTestCaseinstead ofOro\Bundle\ApiBundle\Tests\Functional\RestJsonApiTestCase. By default all API requests are executed by anonymous user. To execute them by the customer user with administrative permissions you can useOro\Bundle\CustomerBundle\Tests\Functional\Api\Frontend\DataFixtures\LoadAdminCustomerUserDatadata fixture, just add$this->loadFixtures([LoadAdminCustomerUserData::class]);insetUp()method of your test class. To execute the test by the customer user with a buyer permissions you can useOro\Bundle\CustomerBundle\Tests\Functional\Api\Frontend\DataFixtures\LoadBuyerCustomerUserDatadata fixture.
Additional notes:
The SetWebsite processor can be used to assign an entity to the current website.
The SetCurrency processor can be used to set the current currency to an entity.
The SetCustomer processor can be used to assign an entity to the current customer.
The SetCustomerUser processor can be used to assign an entity to the current customer user.
An example of registration of such processors:
services:
oro_customer.api.customer_user.set_website:
class: Oro\Bundle\WebsiteBundle\Api\Processor\SetWebsite
arguments:
- '@oro_api.form_property_accessor'
- '@oro_website.manager'
tags:
- { name: oro.api.processor, action: customize_form_data, event: pre_validate, requestType: frontend, parentAction: create, class: Oro\Bundle\CustomerBundle\Entity\CustomerUser, priority: 20 }
oro_order.api.set_currency_to_order:
class: Oro\Bundle\CurrencyBundle\Api\Processor\SetCurrency
arguments:
- '@oro_api.form_property_accessor'
- '@oro_locale.settings'
tags:
- { name: oro.api.processor, action: customize_form_data, event: pre_validate, requestType: frontend, parentAction: create, class: Oro\Bundle\OrderBundle\Entity\Order, priority: 15 }
oro_customer.api.customer_address.set_customer:
class: Oro\Bundle\CustomerBundle\Api\Processor\SetCustomer
arguments:
- '@oro_api.form_property_accessor'
- '@oro_security.token_accessor'
- 'frontendOwner'
tags:
- { name: oro.api.processor, action: customize_form_data, event: pre_validate, requestType: frontend, parentAction: create, class: Oro\Bundle\CustomerBundle\Entity\CustomerAddress, priority: 10 }
oro_customer.api.customer_user_address.set_customer_user:
class: Oro\Bundle\CustomerBundle\Api\Processor\SetCustomerUser
arguments:
- '@oro_api.form_property_accessor'
- '@oro_security.token_accessor'
- 'frontendOwner'
tags:
- { name: oro.api.processor, action: customize_form_data, event: pre_validate, requestType: frontend, parentAction: create, class: Oro\Bundle\CustomerBundle\Entity\CustomerUserAddress, priority: 10 }