{
  "Guid": "SQi97j2AT0eZdEq4dgwM2Q",
  "Document": {
    "Theme": "sandstone",
    "CustomTheme": "",
    "PPTheme": "desert",
    "CustomTheme2": "",
    "HideHeader": false,
    "NoIndex": true,
    "NoSideNav": false,
    "NoExpandCollapse": false,
    "ShowAnchors": false,
    "ShowEditLink": true,
    "Numbered": false,
    "ShowClassification": false,
    "SortOrder": "",
    "Introduction": "Example of how to save data to Docly (only possible from API enabled sites).",
    "Reference": "",
    "ClassificationImage": "",
    "Elements": [
      {
        "ObjectVariant": "Text",
        "Style": "alert alert-danger",
        "NewPage": false,
        "Text": "These functions are only available from the API folder."
      },
      {
        "ObjectVariant": "Chapter",
        "Expand": true,
        "Columns": "",
        "Class": "",
        "Style": "",
        "DefaultCollapsed": false,
        "NewPage": false,
        "Title": "SaveFile(filepath, data, schema)",
        "Elements": [
          {
            "ObjectVariant": "Text",
            "Style": "",
            "NewPage": false,
            "Text": "Saves data from JSON to a new / overwrites DOCLY file. Returns { id, timestamp}."
          },
          {
            "ObjectVariant": "Table",
            "Header": true,
            "EvenColumns": false,
            "NewPage": false,
            "Columns": [
              {
                "Title": "Param"
              },
              {
                "Title": "Type"
              },
              {
                "Title": "Description"
              }
            ],
            "Columns_type": "Columns",
            "Rows": [
              {
                "RowClass": "",
                "Cells": [
                  {
                    "Text": "filepath"
                  },
                  {
                    "Text": "string"
                  },
                  {
                    "Text": "Filepath and name for where to save your document. Filepath is absolute according to site root."
                  }
                ],
                "Cells_type": "Cells"
              },
              {
                "RowClass": "",
                "Cells": [
                  {
                    "Text": "data"
                  },
                  {
                    "Text": "string (json)"
                  },
                  {
                    "Text": "Document data formatted as JSON in string"
                  }
                ],
                "Cells_type": "Cells"
              },
              {
                "RowClass": "",
                "Cells": [
                  {
                    "Text": "schema"
                  },
                  {
                    "Text": "string (filepath or hex)"
                  },
                  {
                    "Text": "What schema to create your Docly file from.\n\n• Specify path to schema file (if it is internal in the site)\n• You can also specify with the document hash (#Dxxxx)\n"
                  }
                ],
                "Cells_type": "Cells"
              }
            ],
            "Rows_type": "Rows"
          },
          {
            "ObjectVariant": "Code",
            "Mode": "javascript",
            "Code": "let data = {\n    \"Notat\" : query.name\n};\nlet file = docly.saveFile(\"#/data/test\", data, \"#/My schema\"); \n\nreturn file;"
          },
          {
            "ObjectVariant": "Text",
            "Style": "",
            "NewPage": false,
            "Text": "Example creates a \"Notat\" document and returns (id, timestamp)."
          },
          {
            "ObjectVariant": "Text",
            "Style": "",
            "NewPage": false,
            "Text": "Note: This example saves data in a # folder to make it unavailable in the published site. (Double ## because first one is escape char)"
          }
        ],
        "Elements_type": "Elements"
      },
      {
        "ObjectVariant": "Chapter",
        "Expand": true,
        "Columns": "",
        "Class": "",
        "Style": "",
        "DefaultCollapsed": false,
        "NewPage": false,
        "Title": "Validation of parameters",
        "Elements": [
          {
            "ObjectVariant": "Text",
            "Style": "",
            "NewPage": false,
            "Text": "Filename: #/API/RegPayment.js"
          },
          {
            "ObjectVariant": "Code",
            "Mode": "javascript",
            "Code": "if (!IsString(query.name)) throw new Error(\"Name is required!\");"
          },
          {
            "ObjectVariant": "Text",
            "Style": "",
            "NewPage": false,
            "Text": "Note that .JS files do not start with #{ like our .hash files.\nAssert throws a validation error in response if statement is true."
          }
        ],
        "Elements_type": "Elements"
      },
      {
        "ObjectVariant": "Chapter",
        "Expand": true,
        "Columns": "",
        "Class": "",
        "Style": "",
        "DefaultCollapsed": false,
        "NewPage": false,
        "Title": "docly.fileExists(filepath)",
        "Elements": [
          {
            "ObjectVariant": "Text",
            "Style": "",
            "NewPage": false,
            "Text": "Returns true if a file exists with this filepath. Filepath is absolute according to site root."
          },
          {
            "ObjectVariant": "Code",
            "Mode": "javascript",
            "Code": "if (docly.fileExists(\"folder1/myfilename\")) {\n    /* file exists */\n}    \nelse {\n    /* file does not exist */\n}"
          }
        ],
        "Elements_type": "Elements"
      },
      {
        "ObjectVariant": "Chapter",
        "Expand": true,
        "Columns": "",
        "Class": "",
        "Style": "",
        "DefaultCollapsed": false,
        "NewPage": false,
        "Title": "DeleteFile(filepath)",
        "Elements": [
          {
            "ObjectVariant": "Text",
            "Style": "",
            "NewPage": false,
            "Text": "Deletes specified file, returns true if deleted Otherwise false."
          },
          {
            "ObjectVariant": "Code",
            "Mode": "javascript",
            "Code": "docly.deleteFile(\"folder1/testfile.txt\");"
          }
        ],
        "Elements_type": "Elements"
      }
    ],
    "Elements_type": "Elements"
  },
  "EmbeddedFiles": [],
  "Schema": "Documentation.5",
  "Tags": [
    "db",
    "store",
    "document",
    "database",
    "function",
    "storage",
    "crud",
    "savefile",
    "fileexists",
    "deletefile"
  ],
  "Modified": "2026-04-23T13:59:37.084508+02:00",
  "Created": "2021-07-18T20:18:54.080746+02:00"
}