REST api v1
REST api (v1)
The MOLGENIS REST API allows you to retrieve and modify your data model entities and entity collections. The API supports all CRUD (create, read, update and delete) methods as well as resource collections paging & filtering and resource field expansion. At the moment of writing JSON and form data are supported as request content types and JSON is the only supported response content type.
Your MOLGENIS data model defines the resources and resource collections that can be accessed and modified. Lets assume that your data model contains the entities DataSet, Protocol and Feature. The REST API will consist of the following endpoints:
tables / entityTypes
Each MOLGENIS table, also known as 'entity collections' or 'entityType' is available with its own end-point. In the examples below 'dataset', 'protocol' and 'feature' are each different tables.
Endpoints
Retrieve data
Each table has its own end-point:
Request
Response
Delete collection
Datasets can be completely deleted (Nb. the meta data will be kept):
Request
Response
Query a collection
Key
Type
Description
start
int
Offset in resource collection
num
int
Number of resources to retrieve starting at start
q
list of molgenis query rule objects
Query to filter the resource collection list
start and num
Request
Response
prevHref is the location of the previous page of resources, nextHref is the location of the next page of resources.
q
Request
Response
Instances
Each data row within a collection (i.e. entity instance) can be accessed via its identifier:
Endpoints
Retrieve
Request
Response
href is the location of this resource, name is a string value and protocol is the location of the entity that this dataset refers to.
Create
By posting a JSON message that matches the meta data attributes you can add new instances:
Request
Response
Update
Existing instances can be updated by putting a complete changed record to the entity instance endpoint:
Request
Response
Update one value
If you only want to change one attribute without needing to provide all other attributes you can put values to the attributes seperately:
Request
Response
Delete
Request
Response
Advanced options
Instance end-points have the following options:
Key
Type
Description
attributes
Comma-separated string
Defines which fields in the API response to select
expand
Comma-separated string
Defines which fields in the API response to (partially) expand
_method
HTTP method
Tunnel request through defined method over default API operation
callback
string
Callback function name used as JSON padding to allow cross domain requests
select attributes
In a query you can specify what attributes to return, useful when having thousands of attributes:
Request
Response
expand xref attributes
MOLGENIS can have attributes of type xref (foreign key) that you can follow and expand attributes of:
Request
Response
partial expand
Within the expansion you can again specify the attributes to be included:
Request
Response
_method
Some browsers do not support operations such as PUT and DELETE. The _method parameter can be used to tunnel the request over a POST operation.
Request
Response
callback
Request
Response
Meta data
Meta data provides details on the attributes within your collection. This allows for client side generation of user interfaces. Assuming that you have entities 'datasets', 'protocol' and 'features' then you can retrieve the metadata as follows:
Endpoints
Retrieve meta data
You can retrieve meta data for each collection:
Request
Response
Delete meta data
Deletes resource meta data and all data associated with this resource.
Request
Response
Authentication
The login route generates a MOLGENIS-token which you can use to access the RESTAPI. When 2-factor-authentication is enabled this route will be disabled if the current user is 2 factor authenticated. For more a detailed description go to 2 factor authentication.
Login
Request
Response
The token can be used as authentication token in subsequent api calls. The token must be added to the http header:
Logout
Request
Response
Response codes
Code
Description
200
Request ok, returned content in body
201
Resource succesfully created
204
Request ok
400
Your request was not valid
401
You are not authorized to perform this operation, did you authenticate?
404
Resource does not exist
500
Request ok but something went wrong on the server
FAQ
How to resolve a 400 Bad Request error?
Did you specify the Content-Type header if your body contains content?
What options exist to define query rules for resource collection requests?
The query rules are serialized Java QueryRule objects, take a look at the source code of the QueryRule class to see what options are available.
Last updated