Concepts

The Labii API is a REST API that provides programmatic access to the Labii platform.

The Labii API is a REST API that provides programmatic access to the Labii platform. It supports all different calling methods, including GET, POST, PUT, and DELETE.

The Labii API is designed to be accessible and flexible, allowing developers to use the programming language and tools of their choice to interact with the Labii platform. The API is fully documented and provides detailed information about each of its endpoints, including the HTTP method, endpoint URL, required parameters, and expected response.

Some of the key features of the Labii API include:

  1. Resource-based architecture: The Labii API uses a resource-based architecture, which means that each endpoint represents a specific resource in the Labii platform, such as a project, experiment, or row.

  2. Authentication and authorization: The Labii API uses OAuth 2.0 for authentication and authorization, ensuring that only authorized users can access sensitive data.

  3. Pagination and filtering: The API provides support for pagination and filtering, allowing developers to retrieve specific subsets of data based on various criteria.

URL

The Labii API uses two types of URLs to represent two different views of an object:

  1. List of objects: {{base_url}}/{app}/{model}/list/{level}/{sid}/{serializer}/

  2. Detail of an object: {{base_url}}/{app}/{model}/detail/{sid}/

The base_url is set to https://www.labii.dev/ by default. If your organization has a dedicated server, you can use https://[your subdomain].labii.dev/ as the base_url.

The app parameter represents the name of the application, while the model parameter represents the name of the model. You can refer to the Labii documentation for more details on these parameters.

The level parameter represents the scope of records to retrieve. You can refer to the Levels section of the Labii documentation for more details on this parameter.

The sid parameter is a static and encrypted Labii object ID. It must match with the level parameter. For example, if level=organization, the sid parameter must be the SID of the organization.

Finally, the serializer parameter represents the scope of fields of the return data. There are three options available:

  • name: Returns only the SID and name of the object, which is very fast.

  • list: Returns selected fields of the objects, which is fast.

  • detail: Returns all fields of the objects, which is slow.

Objects

The Labii API provides various objects that represent different types of entities in the Labii platform, each with a set of methods for interacting with that entity. Below is a list of objects available in the Labii API along with their descriptions, the app they belong to, and their corresponding model:

Levels

Levels define the scope of records to retrieve. The level parameter is a required parameter for the list API. Labii uses the following levels:

  • organization: returns the results within the organization level.

  • user: returns the results for a particular user (deprecated).

  • project: returns the results for a project (deprecated).

Not all levels are available for all list APIs. If a wrong level is used, an HTTP_406_NOT_ACCEPTABLE error will be returned. The table below lists all the allowed levels for each API.

Methods

The following documentation describes the methods used in the Labii API:

  • GET: This method is used to fetch one or more objects.

  • POST: This method is used to create an object.

  • PUT: This method is used to update an object.

  • PATCH: This method is used to partially update an object.

  • DELETE: This method is used to remove an object.

Different roles have different permissions in using the methods. There are five roles at the organization level:

  • Admin: The administrators

  • Member: The members of the organization

  • Alumni: The members who have left the organization

  • User: Other Labii users who do not belong to the organization

  • Anonymous: Unauthorized user

And 3 roles at the project level:

  • Project Admin: The administrator of a project

  • Project Edit: The members have edit permission at the project

  • Project View: The members have view permission at the project

Serializer

The Serializer in Labii API is used to convert the data from the database into a different format. Each Serializer in Labii represents a different field set to be returned. Labii API supports the following serializers:

  • name: This serializer returns the field of sid and name of a record.

  • list: This serializer returns some basic fields. The set of fields varies for different tables.

  • detail: This serializer returns a full set of fields.

Status Codes

Here is a list of status code used by Labii API:

  • HTTP_200_OK: return when API call successful

  • HTTP_201_CREATED: return when an object is created

  • HTTP_204_NO_CONTENT: return when an object is successfully deleted

  • HTTP_401_UNAUTHORIZED: return when the user is not authenticated

  • HTTP_403_FORBIDDEN: return when a user does not have permission

  • HTTP_406_NOT_ACCEPTABLE: return when parameter is not correct

  • HTTP_500_INTERNAL_SERVER_ERROR: return on internal errors

Errors

These are common errors for the list view and detail view.

List view

  • HTTP_401_UNAUTHORIZED - token is not valid

  • HTTP_403_FORBIDDEN - the user does not have permission to perform the action

  • HTTP_406_NOT_ACCEPTABLE - some parameter provided is not acceptable

    • Wrong level - the level provided is not valid or is not allowed

    • Wrong sid - the sid provided can be not decrypted, or does not match any records

    • Wrong field - Error: the field (xxx) is not allowed!

    • Wrong datatype - list, acceptable data is DICT. Please POST multiple times if you have more than one dataset.

Detail view

  • HTTP_401_UNAUTHORIZED - token is not valid

  • HTTP_403_FORBIDDEN - the user does not have permission to perform the action

  • HTTP_406_NOT_ACCEPTABLE - some parameter provided is not acceptable

    • Wrong sid - the sid provided can be not decrypted, or does not match any records

    • Wrong field - Error: the field (xxx) can not be updated!

Example

Get a list of records with curl:

curl -X get https://www.labii.dev/tables/rows/list/organization/xxx/list/ -H "Authorization: Token xxxx"

In Python:

import requests
headers = {
    "X-Forwarded-For": "batch",
    "Content-Type": "application/json",
    "Authorization": "Token %s" % token
}
requests.get(url="https://www.labii.dev/tables/rows/list/organization/xxx/list", headers=headers)

Last updated