magento2: REST API: 'searchCriteria' and 'fields' paramaters can't used with one another to fetch orders

Preconditions (*)

  1. Magento 2.3.1

Steps to reproduce (*)

  1. Create a simple code of REST API with curl to fetch orders with updated_at searchCriteria parameter and fields parameter.
  2. Code as below
$webSiteUrl = 'mydomain.com'
$last1DayUpdated = date('Y-m-d',(strtotime ('-1 day', strtotime(date('Y-m-d')))));
$ch = curl_init("{$webSiteUrl}/rest/V1/orders?searchCriteria[filter_groups][0][filters][0][field]=updated_at&searchCriteria[filter_groups][0][filters][0][value]={$last1DayUpdated}&searchCriteria[filter_groups][0][filters][0][condition_type]=gteq&fields=billing_address,customer_firstname,customer_lastname");

Expected result (*)

  1. Output should json of orders with mentioned fields

Actual result (*)

  1. Output is blank array

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 15 (8 by maintainers)

Most upvoted comments

Hi @jigardhaduk,

The way to use fields with search criteria is different, here is the code:-

$webSiteUrl = ‘mydomain.com’ $last1DayUpdated = date(‘Y-m-d’,(strtotime (‘-1 day’, strtotime(date(‘Y-m-d’))))); $ch = curl_init(“{$webSiteUrl}/rest/V1/orders?searchCriteria[filter_groups][0][filters][0][field]=updated_at&searchCriteria[filter_groups][0][filters][0][value]={$last1DayUpdated}&searchCriteria[filter_groups][0][filters][0][condition_type]=gteq&fields=items[billing_address,customer_firstname,customer_lastname]”);