Skip to content

Rest API

The Metadata Editor offers REST endpoints for schema compilation and field reading. You can find the documentation for the REST API below. Moreover, you can easily access it from the application by clicking on the information icon located at the top-right corner of the form compilation pages.

To test the API, follow these steps:

  • Open the accordion for the desired endpoint below (e.g., the POST endpoint).Click on Try it out , then select Execute .
  • The REST endpoint will be triggered, and the response will be displayed.

For the POST request to api/v1/compile , refer to the example using mri_schema . To visualize this, utilize the Metadata Editor app to render the mri_schema version 8 . When using the api/v1/compile documentation alongside this, you'll notice that the form in the app will automatically populate with the request body values.

Note

For API requests to succeed, ensure that the Metadata Editor is running and the desired schema is selected and loaded.

API swagger documentation

Python API Usage Example

Below is a simple Python code snippet that provides the basic boilerplate for utilizing the REST endpoints.

api/v1/compile

POST.py
import requests

json_data = {
    'study': {
        'studyID': '1.2.840',
        'studyTitle': 'My awesome study',
        'user': {
            'name': 'John',
            'role': 'PI',
        },
        'sample': {
            'sampleName': 'Beautiful solution',
            'sampleID': 'MBS',
        },
        'instrument': {
            'instrumentName': 'MicroSpec 16/885',
            'instrumentID': '4255670',
        },
    },
}

port = 3333
url = f'http://localhost:{port}/api/v1/compile'
requests.post(url, json=json_data)

Info

It may happen to receive a 422 error code, with something like

{
    "error": "Invalid fields",
    "message": "Cannot find [<some keys>] keys in the schema"
}
as a response and still see the document filled in, this happens when some of the fields do not have a match in the schema, while the remaining fileds are correct.

api/v1/read

GET.py
import requests

port = 3333
url = f'http://localhost:{port}/api/v1/read'
response = requests.get(url)
print('Response code:', response.status_code)
print('Response body:', response.json())
You will see a response as:

Response code: 200
Response body: {'study': {'studyID': '1.2.840', 'studyTitle': 'My awesome study', 'user': {'name': 'John', 'role': 'PI'}, 'sample': {'sampleName': 'Beautiful solution', 'sampleID': 'MBS'}, 'instrument': {'instrumentName': 'MicroSpec 16/885', 'instrumentID': '4255670'}}}