Skip to Content

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}/content

Authentication

Required: API key in Authorization header

Authorization: Bearer YOUR_API_KEY

Request

Path Parameters

ParameterTypeRequiredDescription
project_idUUIDYesThe project ID
filenamestringYesThe exact filename (case-sensitive)

Headers

HeaderValueRequired
Content-Typetext/markdownYes

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

StatusErrorDescription
400Bad RequestEmpty content
401UnauthorizedInvalid authentication
404Not FoundFile does not exist
413Payload Too LargeContent 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.mdx

Python (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

  1. Validate content before updating
  2. Create backups before modifying
  3. Track versions in metadata
  4. Use UTF-8 encoding
  5. Handle large files with streaming

See Also

Last updated on