Save data to Docly from API-function Last updated: 06. Nov 2023

Example of how to save data to Docly (only possible from API enabled sites).

These functions are only available from the API folder.

SaveFile(filepath, data, schema)

Saves data from JSON to a new / overwrites DOCLY file. Returns { id, timestamp}.

Param Type Description
filepath string Filepath and name for where to save your document. Filepath is absolute according to site root.
data string (json) Document data formatted as JSON in string
schema string (filepath or hex) What schema to create your Docly file from.

• Specify path to schema file (if it is internal in the site)
• You can also specify with the document hash (#Dxxxx)
var data = {
    "Notat" : query.name
};
var file = docly.saveFile("#/data/test", data, "#/My schema"); 

return file;

Example creates a "Notat" document and returns (id, timestamp).

Note: This example saves data in a # folder to make it unavailable in the published site. (Double ## because first one is escape char)

Validation of parameters

Filename: #/API/RegPayment.js

Assert(!IsString(query.name), "Name is required!");

Note that .JS files do not start with #{ like our .hash files.
Assert throws a validation error in response if statement is true.

FileExists(filepath)

Returns true if a file exists with this filepath. Filepath is absolute according to site root.

if (docly.fileExists("folder1/myfilename")) {
    /* file exists */
}    
else {
    /* file does not exist */
}

DeleteFile(filepath)

Deletes specified file, returns true if deleted Otherwise false.

docly.deleteFile("folder1/testfile.txt");