How to Change in Where Clause / Qurey in Rest API

Hi

How to Change in Where Clause / Qurey in Rest API

http://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_7.5/API/Web_Services/Legacy_REST/SOAP_AP…

Like email extist in Lead module

//The SQL WHERE clause without the word "where".

         'query' => "email1 LIKE mehul@gmail.com",

Tevfik Tümer Matt Marum

  • Hi Mehul,

    The link you've shared with us is from our Legacy Rest API. (Minor edit here: We recommend our customers who are on 7.x to use Rest V10.)

    I'm not really sure what is your approach. If you wanna filter leads. You could use $contains operator in Filters - Developer Guide.

    I hope this helps or feel free to clarify if i get you wrong.

    Best Regards

    Tevfik Tümer

    Developer Support Engineer

  • Hi Tevfik Tümer

    need help on query clause 

       //The SQL WHERE clause without the word "where".

             'query' => "email1 LIKE mehul@gmail.com",

    example i am searching record that having this email in Lead module Using Rest API..

    i have used above link.

  • Hi Mehul,

    I think you are looking something like this;

    $url = $base_url . "/Leads";
    
    // $date_start = date('c');
    $params = array(
        "filters" => array(
          'email1' => array(
            '$contains' => array(
              'mehul@gmail.com'
            )
          )
        )
    );
    
    $records = call($url, $oauth2_token_response->access_token, 'GET', $params);
    

    Hope this helps.

    Best Regards

    Tevfik Tümer

    Developer Support Engineer

  • <?php
        $url = "">mycrm/.../rest.php";
        $username = "mehul";
        $password = "12345";
    
    
        //function to make cURL request
        function call($method, $parameters, $url)
        {
            ob_start();
            $curl_request = curl_init();
       
            curl_setopt($curl_request, CURLOPT_URL, $url);
            curl_setopt($curl_request, CURLOPT_POST, 1);
            curl_setopt($curl_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
            curl_setopt($curl_request, CURLOPT_HEADER, 1);
            curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, 0);
            curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($curl_request, CURLOPT_FOLLOWLOCATION, 0);
       
            $jsonEncodedData = json_encode($parameters);
       
            $post = array(
                "method" => $method,
                "input_type" => "JSON",
                "response_type" => "JSON",
                "rest_data" => $jsonEncodedData
            );
       
            curl_setopt($curl_request, CURLOPT_POSTFIELDS, $post);
            $result = curl_exec($curl_request);
            curl_close($curl_request);
       
            $result = explode("\r\n\r\n", $result, 2);
            $response = json_decode($result[1]);
            ob_end_flush();
       
            return $response;
        }
       
        //login --------------------------------------------
       
        $login_parameters = array(
            "user_auth" => array(
                "user_name" => $username,
                "password" => md5($password),
                "version" => "1"
            ),
            "application_name" => "RestTest",
            "name_value_list" => array(),
        );
       
        $login_result = call("login", $login_parameters, $url);
       
        /*
        echo "<pre>";
        print_r($login_result);
        echo "</pre>";
        */
       
        //get session id
        $session_id = $login_result->id;
       
        //search_by_module -------------------------------------------------
       
        $search_by_module_parameters = array(
            "session" => $session_id,
            'search_string' => '%mehul@gmail.com',
            'modules' => array(
                'Leads',
            ),        'offset' => 0,
            'max_results' => 1,
            'assigned_user_id' => '',
            'select_fields' => array('id'),
            'unified_search_only' => false,
            'favorites' => false
        );
       
        $search_by_module_results = call('search_by_module', $search_by_module_parameters, $url);
       
       
        echo '<pre>';
        print_r($search_by_module_results);
        echo '</pre>';