I would like to have the proper cURL command for getting all pending orders with the products' custom attributes in Magento 2 REST API. I use this, but there are no custom attributes on the products in the result.

curl -X GET -H "Authorization: Bearer xxxxxxxxxxxxxxxxxxxx" -H "Cache-Control: no-cache" 'http://xxxxxx.xxx/index.php/rest/V1/orders?searchCriteria[filter_groups][0][filters][0][field]=status&searchCriteria[filter_groups][0][filters][0][value]=pending'

What am I doing wrong? I get everything but not the product attributes and the custom product attributes.

  • I tried to check the code, but i lost :( Somebody can help me? – chrispooh Nov 24 '15 at 10:37

One order can contain multiple products, which are represented as order items in the context of order. With order APIs you cannot get order list with order items in one request. But it can be done as follows:

  1. Get list of order IDs which you are interested in (e.g. using request provided in the question)
  2. To get product details use \Magento\Sales\Api\OrderItemRepositoryInterface::getList($searchCriteria). Via REST it is available as GET <base_url>/V1/orders/items. Iterate through orders from the previous step and for each one get its items, in search criteria specify filter by order ID

Your Answer

