Docly Developers
Function API only Updated 23 Oct 2026

patchFile(path, patch)

Merges the given properties into an existing document and saves it.

The merge is shallow: each top-level property in the patch replaces the stored one, a nested object is replaced as a whole, and properties you leave out are kept. Both the stored data and the patch must be JSON objects.

If the file only exists in the app (publish template) the site runs from, the site gets its own copy with the patch applied; the app's file is left unchanged. The call runs as the user who published the site, not as the visitor. Check the visitor's own rights with allowModify before you change anything on their behalf.

Parameters

pathstringrequired

Path to the file to patch, from the site root.

patchobjectrequired

Properties to merge into the stored data. Each one replaces the stored property with the same name.

Returns

An object with timestamp, id, guid and filename.

Throws if the file does not exist (error 103), if the path is in #/API/ (error 999), or if the name ends with .hash or .js (error 3).

Example

Normal JavaScript, running in the browser or on the Docly™ server.
// This shows the target file data before update
let targetFileDataBeforePatch = {
    "field1" : "old value 1",
    "field2" : "old value 2",
};

// When running this code:
let patch = { "field1" : "new value 1"};
docly.patchFile("/path/to/file", patch);

// The target file will look like this:
let targetFileDataAfterPatch = {
    "field1" : "new value 1", // This has been updated
    "field2" : "old value 2", // This remains unchanged
};