Document Management Examples
Manage your document library with the SDK.
List and Search Documents
typescript
import { DeIterateClient } from '@deiterate/sdk';
const client = new DeIterateClient({
apiKey: process.env.DEITERATE_API_KEY!,
organizationId: process.env.DEITERATE_ORG_ID,
});
// List all documents
const response = await client.documents.list();
console.log(`Found ${response.data.length} documents`);
// Search documents
const results = await client.documents.search('policy');
console.log(`Found ${results.length} matching documents`);Upload a Document
typescript
async function uploadDocument() {
const document = await client.documents.create({
fileName: 'Information Security Policy.pdf',
docType: 'Policy',
displayName: 'Information Security Policy',
owner: 'security-team@company.com',
classification: 'Internal',
nextReviewDate: new Date('2025-12-01'),
});
console.log(`Created document: ${document.id}`);
}Document Review Workflow
typescript
async function documentReviewReport() {
const response = await client.documents.list();
const now = new Date();
const needsReview = response.data.filter(doc => {
if (!doc.nextReviewDate) return false;
return new Date(doc.nextReviewDate) <= now;
});
console.log(`Documents needing review: ${needsReview.length}`);
for (const doc of needsReview) {
console.log(` ${doc.fileName}`);
console.log(` Review due: ${doc.nextReviewDate}`);
console.log(` Owner: ${doc.owner || 'Unassigned'}`);
}
}Document Status Report
typescript
async function documentStatusReport() {
const response = await client.documents.list();
const byStatus: Record<string, number> = {};
const byType: Record<string, number> = {};
for (const doc of response.data) {
const status = doc.status || 'Unknown';
byStatus[status] = (byStatus[status] || 0) + 1;
const type = doc.docType || 'Unknown';
byType[type] = (byType[type] || 0) + 1;
}
console.log('Documents by Status:');
for (const [status, count] of Object.entries(byStatus)) {
console.log(` ${status}: ${count}`);
}
console.log('\nDocuments by Type:');
for (const [type, count] of Object.entries(byType)) {
console.log(` ${type}: ${count}`);
}
}Mark Document as Reviewed
typescript
async function reviewDocument(docId: string) {
const doc = await client.documents.review(docId, 'Annual review completed');
console.log(`Document reviewed: ${doc.fileName}`);
}