langgenius/dify · error
The server does not support the media type transmitted in th
Error message
The server does not support the media type transmitted in the request.
What it means
Flask `abort(415)` (HTTP 415 Unsupported Media Type) at api/controllers/console/app/workflow.py:637 in the sync-draft-workflow POST handler. The handler accepts only `application/json` (parsed via `request.get_json`) or `text/plain` (raw JSON body validated with `model_validate_json`). Any other Content-Type falls through to the `else: abort(415)` branch. The default werkzeug 415 message is 'The server does not support the media type transmitted in the request.'
Source
Thrown at api/controllers/console/app/workflow.py:637
@rbac_permission_required(RBACResourceScope.APP, RBACPermission.APP_VIEW_LAYOUT)
def post(self, current_user: Account, app_model: App):
"""
Sync draft workflow
"""
content_type = request.headers.get("Content-Type", "")
if "application/json" in content_type:
payload_data = request.get_json(silent=True)
if not isinstance(payload_data, dict):
return {"message": "Invalid JSON data"}, 400
args_model = SyncDraftWorkflowPayload.model_validate(payload_data)
elif "text/plain" in content_type:
try:
args_model = SyncDraftWorkflowPayload.model_validate_json(request.data)
except (ValueError, ValidationError):
return {"message": "Invalid JSON data"}, 400
else:
abort(415)
workflow_service = WorkflowService()
try:
environment_variable_patch = args_model.environment_variable_patch
environment_variable_upserts: list[VariableBase] | None = None
deleted_environment_variable_ids: list[str] = []
if environment_variable_patch is not None:
environment_variable_upsert_mappings = Workflow.normalize_environment_variable_mappings(
environment_variable_patch.environment_variables,
)
environment_variable_upserts = [
variable_factory.build_environment_variable_from_mapping(obj)
for obj in environment_variable_upsert_mappings
]
deleted_environment_variable_ids = environment_variable_patch.deleted_environment_variable_ids
conversation_variables = [
variable_factory.build_conversation_variable_from_mapping(obj)
for obj in args_model.conversation_variablesView on GitHub (pinned to ef8544b173)
Solutions
- Set `Content-Type: application/json` and send a JSON object body.
- If sending a raw JSON string, use `Content-Type: text/plain`.
- Do not use multipart/form-data or form-urlencoded for this endpoint.
Example fix
// before
fetch(url, { method: 'POST', body: formData })
// after
fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload),
}) Defensive patterns
Strategy: validation
Validate before calling
ct = (headers or {}).get("Content-Type", "")
if "application/json" not in ct and "text/plain" not in ct:
raise ValueError("Content-Type must be application/json or text/plain")
# then ensure the body matches the chosen type Type guard
def is_supported_workflow_content_type(value: str) -> bool:
v = (value or "").lower()
return "application/json" in v or "text/plain" in v Try / catch
try:
resp = client.post(f"/console/api/apps/{app_id}/workflows/draft", headers=h, data=body)
except HTTPError as err:
if err.response.status_code == 415:
raise TypeError("set Content-Type to application/json for the sync-draft endpoint") from err
raise Prevention
- Set `Content-Type: application/json` explicitly and send a JSON object body.
- Never use FormData or form-urlencoded for the sync-draft endpoint.
- Unit-test the request with both supported media types to catch regressions.
When it happens
Trigger: POSTing to `/apps/<app_id>/workflows/draft` with a Content-Type header other than `application/json` or `text/plain` — e.g. `multipart/form-data`, `application/x-www-form-urlencoded`, or no Content-Type at all.
Common situations: Client sets Content-Type to `application/json; charset=utf-8` is fine (substring match), but a fetch with `FormData`, a missing header, or a typo like `application/jason` triggers 415.
Related errors
- usage_missing_arg
- patched environment variables require an id
- patched environment variable ids must be unique
- deleted environment variable ids must not be empty
- deleted environment variable ids must be unique
AI-assisted analysis of langgenius/dify@ef8544b173 (2026-08-12).
Data as JSON: /api/errors/15790f5b63cd1a23.
Report an issue: GitHub.