---
title: "REST - Select"
canonical: "https://help.agiloft.com/space/HELP/43714549/REST+-+Select"
format: markdown
---
> Macro (anchor)

The EWSelect operation performs a select on the specified table, and returns the number of records found along with an encoded list of record IDs.

- **Returns**: the number of records found and an encoded list of record IDs.
- **Supported Content-Type**: <span style="color: #505050">application/</span>x-www-form-urlencoded
- Accepts a URL with URL-encoded parameters and record data. For more information about general URL conventions, see [REST Interface](https://agiloft-public.atlassian.net/wiki/spaces/HELP/pages/43715778).
- Additionally, the URL must contain the where clause of the SELECT query to be performed. Queries in the URL must use %N equivalent operators. For instance, in place of `>`, use `%3E%27`.

#### Notes

Only one SQL statement is accepted per call. The API automatically and transparently applies security filters to prevent unauthorized access to information. 

> ⚠️ These SQL queries operate on the database level, and should be written using the dbname column names that can be found in the Table Wizard in user interface. Some values for high-level complex field types may have very different representation from what is seen in the GUI. For example, see [GetChoiceLineId](https://agiloft-public.atlassian.net/wiki/spaces/HELP/pages/43714380) for the special handling of choice values.

The SQL query supplied should only include the `where` clause from a construct similar to: 

```sql
select primary-key-field-name from table-name where ...
```

This returns the number of records found, and an encoded data list of record ID, if any were found.

It is possible to limit the number of records returned using the tools available in the underlying database you use for your instance of Agiloft. For example, if you use MySQL as the underlying database, "limit 0,200" limits the number of the returned records to 200.

The order of records returned is determined by the underlying database, and Select doesn't offer any additional control over this default order. If you need to impose a sort order on the records, consider using [EWSearch](https://agiloft-public.atlassian.net/wiki/spaces/HELP/pages/43717730) instead, where you can specify a saved search that imposes a sort order.

## Example 1

Assume an instance of Agiloft is available on localhost, port 8080 and is called "Demo". List the Service Request records assigned to 'Ralph Knowles'.

The following request is issued: 

```javascript
https://localhost:8080/ewws/EWSelect?$KB=Demo&$login=admin&$password=qwerty&$table=helpdesk_case&$lang=en&where=assigned_person='Ralph Knowles'
```

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

```javascript
EWREST_id_length = '0';
```

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

```javascript
EWREST_id_length = '3';
EWREST_id_0 = '150';
EWREST_id_1 = '169';
EWREST_id_2 = '325';
```

## Example 2

Assume an instance of Agiloft is available on localhost, port 8080 and Demo KB. List the records with summaries containing word 'new’ (summary like '%new%').

The following request is issued: 

```javascript
https://localhost:8080/ewws/EWSelect?$KB=Demo&$login=admin&$password=qwerty&$table=helpdesk_case&$lang=en&where=summary%20like%20%27%25new%25%27
```

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

```javascript
EWREST_id_length = '0'; 
```

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

```javascript
EWREST_id_length = '7';
EWREST_id_0 = '145';
EWREST_id_1 = '147';
EWREST_id_2 = '148';
EWREST_id_3 = '149';
EWREST_id_4 = '151';
EWREST_id_5 = '298';
EWREST_id_6 = '318';
```

## JavaScript Example

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

```javascript
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(' https://localhost:8080/ewws/EWSelect?$KB=Demo&$login=admin&$password=qwerty&$table=helpdesk_case&$lang=en&where=summary%20like%20%27%25new%25%27');
    } 
```

# Error Codes

These error codes are for EWSelect only, but are not an extensive list of possible error codes. For any errors not listed here, consult the General Error Codes section of [https://agiloft-public.atlassian.net/wiki/spaces/HELP/pages/43715778](https://agiloft-public.atlassian.net/wiki/spaces/HELP/pages/43715778).

|  |  |  |  |
| --- | --- | --- | --- |
| **Scenario** | **Type** | **Code** | **Description** |
| Issues while parsing or executing the select query with the   provided input | VALIDATION | 400 | EWWrongDataException   → Error <error> parsing the query <query> |
| Issues while executing the select query | VALIDATION | 500 | EWWrongDataException   → Error executing query, please consult logs |
| Unexpected exception during query execution | VALIDATION | 500 | EWUnexpectedException → Unexpected exception |

> Macro (hide-if)
> 
> #### Related articles
> 
> > Macro (contentbylabel)