Update File Content
Replace the content of an existing Markdown or MDX file. Preserves metadata while updating the file body.
Endpoint
PUT /api/projects/{project_id}/files/{filename}/contentAuthentication
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) |
Headers
| Header | Value | Required |
|---|---|---|
Content-Type | text/markdown | Yes |
Request Body
Raw Markdown/MDX content (max 10MB):
# Updated Article Title
This is the new content...Response
Success Response (200 OK)
{
"filename": "article.mdx",
"project_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"size_bytes": 5120,
"metadata": {
"title": "My Article",
"author": "John Doe"
},
"updated_date": "2025-01-09T16:00:00Z"
}Error Responses
| Status | Error | Description |
|---|---|---|
| 400 | Bad Request | Empty content |
| 401 | Unauthorized | Invalid authentication |
| 404 | Not Found | File does not exist |
| 413 | Payload Too Large | Content exceeds 10MB |
Examples
cURL
curl -X PUT "https://markdownapi.io/api/projects/PROJECT_ID/files/article.mdx/content" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: text/markdown" \
--data-binary @article.mdxPython (httpx)
async def update_file_content(project_id: str, filename: str, content: str):
api_key = os.getenv("MARKDOWN_API_KEY")
async with httpx.AsyncClient() as client:
response = await client.put(
f"https://markdownapi.io/api/projects/{project_id}/files/{filename}/content",
headers={"Authorization": f"Bearer {api_key}", "Content-Type": "text/markdown"},
content=content.encode('utf-8'),
timeout=60.0
)
response.raise_for_status()
return response.json()TypeScript
async function updateFileContent(
projectId: string,
filename: string,
content: string
): Promise<any> {
const response = await fetch(
`https://markdownapi.io/api/projects/${projectId}/files/${filename}/content`,
{
method: 'PUT',
headers: {
'Authorization': `Bearer ${process.env.MARKDOWN_API_KEY!}`,
'Content-Type': 'text/markdown',
},
body: content,
}
);
if (!response.ok) throw new Error(`HTTP ${response.status}`);
return await response.json();
}Best Practices
- Validate content before updating
- Create backups before modifying
- Track versions in metadata
- Use UTF-8 encoding
- Handle large files with streaming
See Also
- Upload File - Upload new files
- Download File - Retrieve content
- Update Metadata - Modify metadata only
- Delete File - Remove files
Last updated on