There are two ways of passing arguments to an endpoint: either encoded as key-value pairs in the URL or encoded as JSON in the body of the request. This depends on the endpoint, in general GET requests will use URL encoding, while POST requests will use JSON encoding. The full specification of all endpoints can be found at the bottom of the page. Here is an example of both methods in Python:
Requests will always return data as JSON with the following structure:
{"request_time": time,"message": data}
It will contain both the time the server has taken to process the request and the actual output. Decode and access the message key to extract the result:
from marple import Marplem =Marple(ACCESS_TOKEN)response = m.get('/version')print(response.json()['message'])# 3.3.0
2 Uploading and Importing Files
In Marple files are uploaded onto a file server and then parsed into our database which we call 'importing'. Once a file has been imported into the database it is referred to as a 'source'.
1. POST /library/file/upload
Upload a file onto the file server.
URL query parameters:
path: the path to the directory on the file server where the file should be uploaded
File body parameters:
file: the file contents
=> Returns "OK", and confirms the path where the file is uploaded
#SetupAPI_URL ='https://app.marpledata.com/api/v1'endpoint ='/library/file/upload'token ='...'auth_header ={'Authorization':f'Bearer {token}'}#Argumentsfiles ={'file':open('myfile.csv', 'rb')}target_dir ='/'# file server root dirtarget_dir ='/sub_dir'# or a subdirectory#Requestr = requests.post(f'{API_URL}{endpoint}', headers=auth_header, params={'path': target_dir}, files=files)#Responser.json()['message'] =={'status':'OK','path':'sub_dir'}
2. POST /library/file/import
Start importing a file into the database.
JSON body parameters:
path: the path to where the file is located on the server
plugin: the plugin to be used for importing the file
config: (optional) the configuration for the plugin
=> Returns the source_id of the file in the database, and the metadata associated with the file
endpoint ='/library/file/import'path ='/sub_dir/myfile.csv'plugin ='csv_plugin'r = requests.post(f'{API_URL}{endpoint}', headers=auth_header, json={'path': path, 'plugin': plugin})r.json()['message'] =={'source_id':1,'metadata':{# most plugins don't support automatic metadata extraction'test_reference':14,}}
Plugins
Marple supports multiple datatypes, each imported with their own plugin. Every plugin also has some available config settings. The config must have the following structure:
To monitor the progression of the file import process, query its status.
The status is a number [0, 100] representing the progress, where 100 means the import has finished successfully.
URL query parameters:
id: source id or array of source ids for which to request the status.
To pass an array as a query parameter use the following syntax:
api_url/sources/status?id=1,2,3,...
Metadata can be manipulated using the /library/metadata endpoints. Metadata is always coupled to files using the source_id and not the file name. The source id associated with a file can be found using the /sources/lookup endpoint.
1. GET /sources/lookup
Get source id associated with file.
URL query parameters:
path: (optional) If the file does not yet have a source_id it can be referenced by its path. This function will return the source id assigned to the file in this case
Marple maintains a public repository with an example API usecase: 🔗 https://gitlab.com/marple-public/marple-api-exampleThis script runs a simulated experiment, logs the data, uploads and imports it into marple and then generates a share link ready for visualisation.In the public repository there are example scripts for both Python and MATLAB.