Importing data into an ontology from a file via API
ES | EN
Introduction
Using the Import tool, you can dump the data from a CSV, JSON or XML file on an existing or on a new ontology (see Creating an ontology by importing an XML from an Open Data Portal ). This tool is also APIfied, meaning that you can invoke it via API through a simple HTTP REST request.
Â
Invoking from Swagger
If you access the Control Panel’s APIs from the header and look for the option "Import tool" in the drop-down menu, the Swagger interface of this API will appear:
Â
Â
And a POST operation to make the import:
Select this operation and fill in the parameters:
Authorization: introduced in the request's header, it represents the user's Oauth2 token. You can get it by clicking on the APIs button in the Control Panel header.
newOntology: specifies whether you want to create a new ontology (true) to dump the file’s data there, or to do it over an existing one (false).
ontologyName: name of the ontology where the file’s data will be imported. If the field newOntology is set to false, it will have to be the name of an existing ontology to which the user has permission. If, on the other hand, it is set to true, it will have to be a valid ontology name, and there cannot be another ontology with the same name.
ontologyDescription: short description of the new ontology to be created to import data. This parameter is only required to fill in if newOntology has been set to true.
file: CSV, XML or JSON file with the data to be imported.
Once these parameters have been filled in, click on Execute and, if everything works correctly, the result will be a code 200.
If you access the list of ontologies (DEVELOPMENT → My Ontologies), you can see your newly-created ontology:
And from the query tool (TOOLS → Query Tool), you will see that the data have been inserted correctly:
Â
Invocation from Postman
If you have the Postman application, you can make the HTTP request from there. In this case, you are going to import a new data from a JSON file into the already existing Restaurants ontology.
To do this, select POST as the HTTP method, configure the API’s URL and fill in the necessary parameters from the Params tab:
In the request’s headers, include the Oauth2 token:
Finally, in the request’s body, include the file:
Click on the Send button and, if the request returns a code 200:
Then you can access the query tool (TOOLS → Query Tool) in the Control Panel to check that the new data have been correctly inserted:
Â
Â
Â