The EWSearch REST operation:

All parameters and names must be properly URL-encoded.


Ad Hoc Searches

In opposition to saved searches, ad hoc searches are limited to run-time queries using the 'query' clause. An example of such a REST query is shown below using the conditions &query=summary like '%25test' %26%26 priority=3:

http://localhost:8080/ewws/EWSearch?$KB=Demo&$table=case&$login=admin&$password=qwerty&$lang=en&query=summary like '%25test' %26%26 priority=3

Pagination

Examples of REST Searches

Assume an instance of  is available on localhost, port 8080 and the knowledgebase is called 'Demo'. List the Service Request records that correspond to the saved search 'C: Status is Closed'. Additionally, only return those that have High priority.

The following request is issued: 

http://localhost:8080/ewws/EWSearch?$KB=Demo&$login=admin&$password=qwerty&$table=helpdesk_case&$lang=en&search=C%3A%20Status%20is%20Closed&query=priority%3DHigh

If there are no records found, the following result will be returned: 

 EWREST_id_length = '0';

The following result will be returned in the case of four records being found. 

If no return fields are specified in the request, it will return the ID, type fields and requester login field, based on the record ownership defined for the Service Request table, based on the permissions definition for the Service Request table.

EWREST_length = '4';
EWREST_login_0='ewsystem';
EWREST_type_0='helpdesk_case';
EWREST_id_0='318';
EWREST_login_1='ewsystem';
EWREST_type_1='helpdesk_case';
EWREST_id_1='151';
EWREST_login_2='ewsystem';
EWREST_type_2='helpdesk_case';
EWREST_id_2='146';
EWREST_login_3='internal';
EWREST_type_3='helpdesk_case';
EWREST_id_3='145';

Assume an instance of  is available on localhost, port 8080 and Demo KB. Now we want to retrieve particular fields. 

The following request is issued: 

http://localhost:8080/ewws/EWSearch?$KB=Demo&$login=admin&$password=qwerty&$table=helpdesk_case&$lang=en&search=C%3A%20Status%20is%20Closed&query=priority%3DHigh&field=summary&field=priority 

If there are no records found, the following result will be returned: 

EWREST_id_length = '0';

The following result will be returned in the case of four records being found: 

EWREST_length = '4';
EWREST_summary_0='Here is a new service request with some tasks';
EWREST_priority_0='High';
EWREST_summary_1='New Employee Setup for Patricia Smith';
EWREST_priority_1='High';
EWREST_summary_2='Upgrading Our Software';
EWREST_priority_2='High';
EWREST_summary_3='Need New Wireless Card for Laptop';
EWREST_priority_3='High';    

Assume an instance of  is available on localhost, port 8080 and Demo KB. Now we want to retrieve particular fields in addition to the default ones as per Example 2. 
We are retrieving data in pages 2 records at a time and are interested in the 2nd page only. Page numbers counts from 0.

The following request is issued: 

http://localhost:8080/ewws/EWSearch?$KB=Demo&$login=admin&$password=qwerty&$table=helpdesk_case&$lang=en&search=C%3A%20Status%20is%20Closed&query=priority%3DHigh&field=summary&field=priority&page=1&limit=2

If there are no records found, the following result will be returned: 

EWREST_id_length = '0';

The following result is returned in the case of four records found in total, showing last two ones: 

EWREST_length = '2';
EWREST_summary_0='Upgrading Our Software';
EWREST_priority_0='High';
EWREST_summary_1='Need New Wireless Card for Laptop';
EWREST_priority_1='High';

Here is an example for a JavaScript-based client that invokes the REST interface via AJAX: 

    function xmlhttpGet (strURL) {
        var xmlHttpReq=false;
        var self=this;
        // Mozilla/Safari
        if (window.XMLHttpRequest) {
            try {
                netscape.security.PrivilegeManager.
enablePrivilege("UniversalBrowserRead");
            } catch (e) {
                alert("Permission UniversalBrowserRead denied.");
            }
            self.xmlHttpReq=new XMLHttpRequest();
        }// IE
        else if (window.ActiveXObject) {
            self.xmlHttpReq=new ActiveXObject("Microsoft.xmlHTTP");
        }
        self.xmlHttpReq.open('GET', strURL, true);
        self.xmlHttpReq.onreadystatechange=requestComplete;
        self.xmlHttpReq.send(null);
    }
    function requestComplete() {
        if (xmlHttpReq.readyState==4||xmlHttpReq.readyState=="complete") {
            eval (self.xmlHttpReq.responseText);
            alert ("Id of new ticket"+EWREST_id);
        }
    }
    function main() {
        xmlhttpGet('
http://localhost:8080/ewws/EWSearch?$KB=Demo&$login=admin&$password=qwerty&$table=helpdesk_case&$lang=en&search=C%3A%20Status%20is%20Closed&query=priority%3DHigh&field=summary&field=priority');
    } 

Related articles