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 onTry it out
, then selectExecute
. - 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
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
api/v1/read
You will see a response as: