We have created a public API collection for Order Attributes module with all available queries and sample data that you can both test via our demo endpoints and copy to run local tests in your Magento environment. More details about using public collections can be found in the following FAQ post.
1. Amasty\Orderattr\Api\EntityDataRepositoryInterface - class for managing order attributes in the backend:
- POST /V1/amasty_orderattr/entityData, method="save" - create an attribute;
- PUT /V1/amasty_orderattr/entityData/:entityId, method="save" - edit an attribute;
- DELETE /V1/amasty_orderattr/entityData/:entityId, method="deleteById" - delete an attribute;
- GET /V1/amasty_orderattr/entityData, method="getById" - get information about an attribute;
- GET /V1/amasty_orderattr/entityData/all, method="getList" - get a list with attributes;
- GET /V1/amasty_orderattr/entityData/:orderId, method="getByOrderId - get information about an attribute by its ID.
2. Amasty\Orderattr\Api\CheckoutDataRepositoryInterface - class for managing order attributes on checkout for registered users:
- POST /V1/amasty_orderattr/checkoutData, method="save" - add an order attribute on checkout for a logged-in user.
3. Amasty\Orderattr\Api\GuestCheckoutDataRepositoryInterface - class for managing order attributes on checkout for logged-in users:
- POST /V1/amasty_orderattr/guestCheckoutData, method="save" - add an order attribute on checkout for a guest.
If it is necessary to retrieve the order ID using an order attribute value in the Order Attributes API module, you need to use a GET request with the following format:
- {{base_url}}/rest/all/V1/amasty_orderattr/entityData/all?searchCriteria
The key parameters are:
- "parent_entity_type": 1 means that the order attribute is part of the order, whereas 2 means it is part of the quote
- "parent_id": 3 - if parent_entity_type is 1, then parent_id corresponds to order_id, and if it is 2, it corresponds to quote_id
For example, to retrieve all orders where attribute_code is amasty_test_order_attr_code and attribute_value is test_2, you can use the following query:
{{base_url}}/rest/all/V1/amasty_orderattr/entityData/all?searchCriteria[filter_groups][0][filters][0][field]=amasty_test_order_attr_code&searchCriteria[filter_groups][0][filters][0][value]=test_2&searchCriteria[filter_groups][0][filters][0][condition_type]=eq&searchCriteria[filter_groups][1][filters][0][field]=parent_entity_type&searchCriteria[filter_groups][1][filters][0][value]=1&searchCriteria[filter_groups][1][filters][0][condition_type]=eq
The results of this request can be seen in the screenshot
This screenshot shows that orders 4 and 6 have the attribute_code amasty_test_order_attr_code with the attribute_value test_2. This is also confirmed by the order grid visible in the screenshot