Get a Project Name

Projects contain a collection of samples submitted to the lab for a specific goal or purpose. Often, a script needs information recorded at the project level to do its task. In this simple example, an HTTP GET against a project is shown to obtain information on the project in XML.

Prerequisites

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

  • A project exists with name "HTTP Get Project Name with GLS Utils".

  • The LIMS ID of the project above, referred to as <project limsid>.

  • A compatible version of API (v2 r21 or later).

Code Example

The easiest way to find a project in the system is with its LIMS ID.

  • If the project was created in the script (with an HTTP POST) then the LIMS ID is returned as part of the 201 response in the XML.

  • If the LIMS ID is not available, but other information uniquely identifies it, you can use the project (list) resource to GET the projects and select the right LIMS ID from the collection.

Working with list resources generally requires the same script logic, so if you need the list of projects to find a specific project then review Find an Account Registered in the System example. This example demonstrates listing and finding resources for labs, but the same logic applies.

Step 1. Determine the Project's URI

The first step is to determine the URI of the project:

// Determine the project's URI
URI projectURI = new URI("http://${hostname}/api/v2/projects/${projectID}")

Step 2. Retrieve the Project Resource

Next, use the project LIMS ID to perform an HTTP GET on the resource, and store the response XML in the variable named projectNode:

// Get a single Project by limsid
projectNode = GLSRestApiUtils.httpGET(projectURI.toString(), username, password)
println GLSRestApiUtils.nodeToXmlString(projectNode) 

The projectNode variable can now be used to access XML elements and/or attributes.

Step 3. Obtain the Project Name

To obtain the project's name ask the projectNode for the text representation of the name element:

// Obtain the name
println("Project ID : ${projectNode.name.text()}")

Expected Output and Results

<prj:project xmlns:prj="http://genologics.com/ri/project" uri="http://yourIpAddress/api/v2/projects/LUN3" limsid="LUN3">
  <name>HTTP Get Project Name with GLS Utils</name>
  <open-date>2017-05-31</open-date>
  <researcher uri="http://yourIpAddress/api/v2/researchers/1"/>
  <permissions uri="http://yourIpAddress/api/v2/permissions/projects/LUN3"/>
</prj:project>

Attachments

GetProjectName.groovy:

Last updated