Importer 4

Importer: Import Via Webservice (REST)

The import process: How to import documents with the importer webservice.

Import via webservice

The main difference between an import via webservice and via watchfolder is the way of passing the files to the importer. After the files to import are handed over to the Importer, the process is mostly identical. The webservice offers the same functionality as the watchfolder mechanism. In addition to the watchfolder mechanism, the webservice returns a JSON description of the import status instead of just writing message to the log. It is also possible to send parameters along with the data to import, which can be accessed by preprocessor scripts or XSL transformations.

First of all, the webservice has to be activated and configured in the base configuration file application.yml. It is not recommended to switch on the webservice if not needed. The webservice can also be disabled for specific instances in the instance configuration. Then, an error will be thrown when trying to import documents via webservice using this instance.

To secure the webservice you can enable basic authentication using the configuration option importer.webService.authenticationRequired. The usernames and passwords must be configuration using the option importer.webService.logins.

Once the webservice is configured and running, you may use the POST request method at the URL /v1/import/<instanceKey> with following information:

Using data in POST request
DataDescription
<instanceKey>Path variable to define the importer instance the data is sent to. <instanceKey> refers to the instance key from the instance configuration.
Request bodyThe data enclosed in the body of the request message is passed to the selected instance.
Query parametersOptional request parameters in the URL as key-value paars (?key1=value1&key2=value2) are passed to the preprocessor scripts and XSL transformation of the selected instance.

Webservice Response

The webservice returns a JSON description of the import status. A webservice response might look like the following example:

{
  "successful": true,  
  "importDeferred": false,
  "importDate": "2023-06-18T13:11:32.083+00:00", 
  "duration": 0.262, 
  "importFilePath": "/cms/importer/my-instance/success/ws_1687093891817_0.xml", 
  "preprocessedFilePath": "/cms/importer/my-instance/success/ws_1687093891817_0_preProcessed.xml", 
  "documents": [ 
    {
      "sophoraId": "rest-import100", 
      "externalId": "rest-import", 
      "uuid": "a5aa1680-bf10-499b-afe7-bc4f00362043",
      "newlyCreated": false, 
      "successfullySaved": true 
      "resourceDocuments": [ 
        { 
          "sophoraId": "rest-import-resource100", 
          "externalId": "rest-import-resource", 
          "uuid": "182aff73-a898-4a3d-bdc4-57402e3e1e4e", 
          "newlyCreated": true, 
          "successfullySaved": true,
          "resourceDocuments": [ ... ] 
        }
      ]
    }
  ]
}

In the example above, two sophora documents were imported: a main document and a document referenced as resource (<resourceList> in the sophora XML of the main document).

Information about the import process:

PropertyDescription
successfulIndicates if the import process was altogether successful. This means that any content that should be imported has been imported.
Note: In any case there may have been warnings occurred during the import process which are collected in the property errorText.
importDeferredIf the result import XML contained the forceLock-Element with a timeout, the importer might defer the import if the respective document is locked. In this case, the POST method call returns before the import finishes and contains this attribute set to true.
errorTextText with errors and warnings which occurred during the import process of documents. Can be omitted if no problems occurred.
importDateShows the time of the import in the time format "ISO 8601" - "2010-07-29T15:11:54.568+02:00" for instance.
durationShows the duration (in seconds) of the import process.
importFilePathThe complete path of the file with data from the request body. This file is located either in the successful or in the failure folder of the importer instance.
preprocessedFilePathThe complete path of the file after the preprocessor script modified the data. This file is located either in the successful or in the failure folder of the importer instance.
transformedImportFilePathThe complete path of the transformed file (if an xsl transformation was made). This file is located either in the successful or in the failure folder of the importer instance.
documentsInformation about sophora documents which were handled during the import process (see next table).

Information about a particular document import:

PropertyDescription
newlyCreatedShows if the sophora document was newly created (true) or if an existing document was updated (false).
Note: If the import of the document was not successful (i.e. the property successfullySaved is false), this property has no informative value.
successfullySavedIndicates whether the document was successfully saved in the repository.
sophoraIdThe sophora id of the processed document.
Note: If the import of the document was not successful (i.e. the property successfullySaved is false), this property may be empty or only set with the provided id stem of the document to be imported.
externalIdThe external id of the processed document.
Note: If the import of the document was not successful (i.e. the property successfullySaved is false), this property may be empty.
uuidThe uuid of the processed document.
Note: If the import of the document was not successful (i.e. the property successfullySaved is false), this property may be empty.
resourceDocumentsInformation about documents which are placed in the element <resourceList> of the result sophora import XML.

Last modified on 6/16/23

The content of this page is licensed under the CC BY 4.0 License. Code samples are licensed under the MIT License.

Icon