Download File
Download the content of a Markdown or MDX file from a project. Returns the raw file content.
Endpoint
GET /api/projects/{project_id}/files/{filename}Authentication
Required: API key in Authorization header
Authorization: Bearer YOUR_API_KEYRequest
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
project_id | UUID | Yes | The project ID |
filename | string | Yes | The exact filename (case-sensitive) |
Response
Success Response (200 OK)
Headers:
Content-Type: text/markdown; charset=utf-8
Content-Length: 4096
Content-Disposition: attachment; filename="article.mdx"
X-File-Size: 4096
X-Created-Date: 2025-01-09T10:00:00Z
X-Updated-Date: 2025-01-09T10:00:00ZBody: Raw file content
Error Responses
| Status | Error | Description | Solution |
|---|---|---|---|
| 401 | Unauthorized | Missing or invalid authentication | Verify credentials |
| 404 | Not Found | Project or file does not exist | Verify project_id and filename |
| 429 | Too Many Requests | Rate limit exceeded | Retry with backoff |
Examples
cURL
curl "https://markdownapi.io/api/projects/PROJECT_ID/files/article.mdx" \
-H "Authorization: Bearer YOUR_TOKEN" \
-o article.mdxPython (httpx)
import httpx
import os
async def download_file(project_id: str, filename: str, output_path: str | None = None):
api_key = os.getenv("MARKDOWN_API_KEY")
async with httpx.AsyncClient() as client:
response = await client.get(
f"https://markdownapi.io/api/projects/{project_id}/files/{filename}",
headers={"Authorization": f"Bearer {api_key}"},
timeout=60.0
)
response.raise_for_status()
content = response.text
if output_path:
with open(output_path, 'w', encoding='utf-8') as f:
f.write(content)
print(f"✓ File downloaded: {output_path}")
return contentTypeScript
async function downloadFile(
projectId: string,
filename: string,
outputPath?: string
): Promise<string> {
const apiKey = process.env.MARKDOWN_API_KEY;
const response = await fetch(
`https://markdownapi.io/api/projects/${projectId}/files/${filename}`,
{
headers: { 'Authorization': `Bearer ${apiKey!}` },
}
);
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
}
const content = await response.text();
console.log('✓ File downloaded');
return content;
}See Also
- Upload File - Add files to project
- List Files - View files in project
- Update Content - Modify file content
- Delete File - Remove files
Last updated on