Read Document as Markdown
Extract document content as markdown text. Your agent should use this to read documents before editing and verify changes after edits are applied.
Path Parameters
The unique identifier of the document (UUID)
Request Body
Client-provided UUID for idempotency and tracking. Generate a new UUID for
each read request.
Response
The UUID of the read operation (same as request)
Markdown representation of the document content
Time taken to generate the markdown in seconds
Code Examples
import { v4 as uuidv4 } from "uuid";
const docId = "a1b2c3d4-e5f6-7890-abcd-ef1234567890";
const response = await fetch(
`https://api.agentoffice.dev/v1/documents/${docId}/markdown`,
{
method: "POST",
headers: {
Authorization: "Bearer YOUR_API_KEY",
"Content-Type": "application/json",
},
body: JSON.stringify({
readUid: uuidv4(),
}),
}
);
const data = await response.json();
console.log("Markdown content:");
console.log(data.markdown);
Example Response
{
"readUid": "550e8400-e29b-41d4-a716-446655440000",
"markdown": "# Q4 Financial Report\n\n## Executive Summary\n\nThis report covers the financial performance for Q4 2024...\n\n## Revenue Analysis\n\n- Total Revenue: $2.5M\n- Growth: 15% YoY\n\n## Conclusion\n\nThe company showed strong performance in Q4.",
"timeToGenerate": 2.1,
"documentName": "report.docx",
"documentId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
}
Use Cases
Content Extraction
Extract document content for search indexing or data processing
AI Integration
Feed document content to LLMs for analysis or summarization
Version Control
Track document changes in markdown-friendly version control systems
Web Display
Display document content on websites using markdown renderers
Processing Markdown Content
Here’s how to use the markdown output in different scenarios:
import { v4 as uuidv4 } from "uuid";
// Get markdown
const response = await fetch(
`https://api.agentoffice.dev/v1/documents/${docId}/markdown`,
{
method: "POST",
headers: {
Authorization: `Bearer ${API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ readUid: uuidv4() }),
}
);
const { markdown } = await response.json();
// Search for specific content
if (markdown.includes("financial report")) {
console.log("Found financial report content");
}
// Extract headers
const headers = markdown.match(/^#{1,6} .+$/gm);
console.log("Document headers:", headers);
The markdown output preserves document structure including:
- Headings: Converted to markdown headers (# ## ###)
- Lists: Bullet points and numbered lists
- Tables: Formatted as markdown tables
- Bold/Italic: Text formatting preserved
- Links: Hyperlinks maintained
- Images: Image references with descriptions (if available)
Example Conversion
Original Document
Markdown Output
A Word document with:
- Heading: “Financial Report”
- Bold text: “Q4 Results”
- Table with revenue data
- Bulleted list of achievements
Alternative: Get Markdown During Upload
You can also request markdown when uploading a document by setting return_markdown=true
:
const formData = new FormData();
formData.append("file", file);
formData.append("return_markdown", "true");
const response = await fetch("https://api.agentoffice.dev/v1/documents/", {
method: "POST",
headers: { Authorization: `Bearer ${API_KEY}` },
body: formData,
});
const { docId, markdown } = await response.json();
console.log("Markdown:", markdown);
Queue Processing
Like edits, markdown read operations are queued per document to ensure consistency:
// Multiple read requests to the same document are processed sequentially
const read1 = fetch(
`https://api.agentoffice.dev/v1/documents/${docId}/markdown`,
{
method: "POST",
headers: {
Authorization: `Bearer ${API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ readUid: uuidv4() }),
}
);
const read2 = fetch(
`https://api.agentoffice.dev/v1/documents/${docId}/markdown`,
{
method: "POST",
headers: {
Authorization: `Bearer ${API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ readUid: uuidv4() }),
}
);
// Both will complete, processed in order
const [result1, result2] = await Promise.all([read1, read2]);
Error Responses
{
"detail": "Document not found or has expired"
}
Markdown generation typically takes 1-5 seconds depending on document
complexity.