How to combine filters in URL?

I was looking for examples on how to use the filters in the URL and found this:

In these examples they have the filters in a more 'readable' format:
/rest/v10/Accounts/demo_burger_palace/link/contacts?filter[0][last_name][$starts]=b&filter[0][first_name][$starts]=b&filter[0][$favorite]=_this&fields=name,first_name,last_name,email,description
So if I wanted to filter by
((first_name starts with F) OR (first_name starts with A)) AND (last_name equals Shiekh) the array format would be:
$filter = array (
  array( //the And
    array( //the first element of the And
      'last_name' => array('$eq' => 'shiekh')
    ),
    array( //the second element of the And
      '$or' => array( //the OR
         array( //the first element of the Or
           'first_name'=>array('$starts' => 'F)
         ),
         array( //the second element of the Or
           'first_name => array('$starts' => 'A')
         ),
     ), //close the Or
  ), //close the And
) //close the filter
But I have not yet figured out how to get the "or" into a filter URL
I would think the parts would be something like:
filter[0][last_name][$eq]=Shiekh
filter[1][first_name][$starts]=F
 
filter[2][first_name][$starts]=A
But how to combine the three?
thanks,
FrancescaS
  • Hi Francesca,

    It is actually really simply. Whenever you use an operator consider that Sugar will iterate all the items of that definition. 

    Looking into your definition; 

    $filter = array(
        array(
            'last_name' => "shiekh"
        ),
        array(
            '$or' => array(
                array(
                    'first_name' => array(
                        '$starts' => "F",
                    ),
                ),
                array(
                    'first_name' => array(
                        '$starts' => "A",
                    ),
                ),
            ),
        ),
    );

    You are looking for this;

    filter[0][last_name]:shiekh
    filter[1][$or][0][first_name][$starts]:F
    filter[1][$or][1][first_name][$starts]:A

    Edit:  Additionally, Have a look at Filters - Developer Guide documentation. Your operator doesn't seem correct. It needs to be $equals rather than $eq.

    Best Regards
    Tevfik Tümer
    Developer Support Engineer