# Find an Account Registered in the System

Imagine that each month the new external accounts with which your facility works are contacted with a Welcome package. In this scenario, it would be helpful to obtain a list of accounts that have been modified in the past month.

**NOTE**: In Clarity LIMS v2.1 and later, the term Labs was replaced with Accounts. However, the API resource is still called labs.

### Prerequisites

Before you follow the example, make sure you have the following items:

* Several accounts exist in the system.
* At least one of the accounts was modified after a specific date.
* A compatible version of API (v2 r21 or later).

### Code Example <a href="#example" id="example"></a>

In LIMS v6.2 and later, in the **Configuration > User Management** page, the **Accounts** view lists the account resources available.

To obtain a list of all accounts modified after a specific date, you can use a GET request on the **accounts list** resource and include the **?last-modified** filter.

To specify the last month, a **Calendar** object is instantiated. This Calendar object is initially set to the date and time of the call, rolled back one month, and then passed as a query parameter to the GET call.

```
// Retrieve and format a date
c = Calendar.getInstance()
c.add(Calendar.MONTH, -1)
df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
time = df.format(c.getTime()).replace('+', '%2B')
 
// Filter labs by last-modified on specified date
labsURI = "http://${hostname}/api/v2/labs?last-modified=" + time
labs = GLSRestApiUtils.httpGET(labsURI, username, password)
 
// For each lab, retrieve it
labs.'lab'.each {
    labResource = GLSRestApiUtils.httpGET(it.@uri, username, password)
    println "Welcome to the team, ${labResource.name.text()}"
    labState = labResource.'shipping-address'.state.text()
     
    // If lab is in Washington, print message
    if (labState == "WA") {
        println "Go Huskies!"
    }
}
```

The first GET call returns a list of the first 500 labs that meet the date modified criterion specified. The script iterates through each lab element to look at individual lab details. For each lab, a second GET method populates a lab resource XML node with address information.

The REST list resources are paged. Only the first 500 items are returned when you query for a list of items, (eg, <http://youripaddress/api/v2/artifacts>).

If you cannot filter the list, it is likely that you must iterate through the pages of a list resource to find the items that you are looking for. The URI for the next page of resources is always the last element on the page of a list resource.

### Expected Output and Results <a href="#results" id="results"></a>

In the following example, the XML returned lists three out of the four labs, excluding one due to the date filter:

```
<lab:labs>
    <lab uri="http://yourIPaddress/api/v2/labs/2">
       <name>Administrative Lab</name>
    </lab>
    <lab uri="http://yourIPaddress/api/v2/labs/52">
      <name>Giant Facility</name>
    </lab>
    <lab uri="http://yourIPaddress/api/v2/labs/102">
      <name>University West</name>
    </lab>
</lab:labs>
```

One of the labs has 'WA' recorded as the state, adding a second printed line to the output:

```
Welcome to the team, Administrative Lab
Welcome to the team, Giant Facility
Welcome to the team, University West
Go Huskies!
```

### Attachments

GetLab.groovy:

{% file src="<https://2084401275-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfjuebS41N49G1Eh55hP7%2Fuploads%2Fgit-blob-507481c448116a488b066229eb0dc5fdb8584e54%2FGetLab.groovy?alt=media&token=01784e26-54a3-428a-a9ec-f2a943f3ac1d>" %}
