Remember, all data stored on Context is public. Avoid storing any secrets or private information without additional measures to protect confidentiality.
Fetch Documents
Fetch a specific document or template or asset, from any domain:
// Fetch a specific document
const document = await ctx.document("context.startup/link3"); // "domain/path/to/file"
You can fetch a specific version of a document in two different ways:
// By using the version method of the document:
const document = await ctx.document("document_path");
const documentVersion = await document.data.getVersion("X.Y.Z");
// By specifying the version directly the document path:
const documentInVersionXYZ = await ctx.document("document_path?v=X.Y.Z");
Create a Document
Steps to create a new document within a domain:
const data = YOUR_JSON_DATA; // JSON data for the document
const templates = ["template_path"]; // Optional array of template paths
const metadata = { name: "Document Name", description: "Document Description", readme: "ctx:domain/files/my_markdown" }; // Optional metadata
const documentPath = "mypath/files/document";
const newDocument = await ctx.createDocument(documentPath, data, templates, metadata);
Update a Document
Update an existing document:
const updatedData = YOUR_UPDATED_JSON_DATA; // Updated JSON data
const document_path = "mypath/files/document";
const document = await ctx.document(documentPath);
if (!document.success) {
// Handle error
}
const result = await document.data.update(updatedData);
Adding Metadata to a Document
You can add metadata to a document using the addMetadata method. The metadata object should contain the following (optional) fields: name, description, and readme as shown below: