wiki:MolgenisRestInterface

Posting data to MOLGENIS using REST API

Using simple GET commands

The current REST API uses CSV to add/delete records. Say for example that we want to upload the following CSV to 'Invidual':

Name,Description
Ind1,Desc
Ind2,Desc2

Therefore In javascript just call the following URL

http://localhost/molgenis_apps/api/add?data_type_input=org.molgenis.pheno.Individual&data_input=Name,Description%0AInd1,Desc1%0AInd2,Desc2&data_action=ADD

Note that the path is:

Explanation of parameters:

name description example
data_type_input the entity type to be uploaded org.molgenis.pheno.Individual
data_input the data in CSV format, columns must be known in data_type_input Name,Description
Ind1,Desc
Ind2,Desc2
data_action the desired action. Either 'ADD' or 'REMOVE'. For remove you only need to provide primary key (usually 'id'). ADD

Using CURL

You can use CURL in two ways.

  1. using inline csv using %0 as newline
  2. by creating your data in csv and uploading

Two silly examples:

(Option A) inline csv

curl -d 'data_type_input=org.molgenis.pheno.Individual&data_input=Name,Description%0AInd1,Desc1%0AInd2,Desc2&data_action=ADD' http://vm7.target.rug.nl/ngs_test/api/add

(Option B) file upload

curl 
-F data_type_input=org.molgenis.pheno.Individual 
-F data_file=@/Users/robert/data_individual.txt 
-F data_action=ADD 
-F data_silent=F 
-F submit_input=submit 
http://vm7.target.rug.nl/ngs_test/api/add

MOLGENIS has a feature to upload CSV files via a webform. Here for example,  http://vm7.target.rug.nl/ngs_test/api/add. Here we show how to use this form from the commandline. In other words: this is like programmatically submitting a html form.

Here the meaning of the parameters is:

  • data_type_input = how to handle the upload (in this example: upload Individual CSV)
  • data_field = reference to the file containing CSV
  • data_action = how to treat the upload, here ADD each row from CSV to datab ase
  • data_silent = ???
  • submit_input = the action itself (triggers the upload)
  • final parameter is the url for this post

where data_individual.txt:

Name,Description Ind1,Desc1 Ind2,Desc2 Ind2,Desc2 Ind2,Desc2