{"record":{"id":"15790f5b63cd1a23","repo":"langgenius/dify","slug":"the-server-does-not-support-the-media-type-transmi","errorCode":null,"errorMessage":"The server does not support the media type transmitted in the request.","messagePattern":"The server does not support the media type transmitted in the request\\.","errorType":"http","errorClass":null,"httpStatus":415,"severity":"error","filePath":"api/controllers/console/app/workflow.py","lineNumber":637,"sourceCode":"    @rbac_permission_required(RBACResourceScope.APP, RBACPermission.APP_VIEW_LAYOUT)\n    def post(self, current_user: Account, app_model: App):\n        \"\"\"\n        Sync draft workflow\n        \"\"\"\n        content_type = request.headers.get(\"Content-Type\", \"\")\n\n        if \"application/json\" in content_type:\n            payload_data = request.get_json(silent=True)\n            if not isinstance(payload_data, dict):\n                return {\"message\": \"Invalid JSON data\"}, 400\n            args_model = SyncDraftWorkflowPayload.model_validate(payload_data)\n        elif \"text/plain\" in content_type:\n            try:\n                args_model = SyncDraftWorkflowPayload.model_validate_json(request.data)\n            except (ValueError, ValidationError):\n                return {\"message\": \"Invalid JSON data\"}, 400\n        else:\n            abort(415)\n        workflow_service = WorkflowService()\n\n        try:\n            environment_variable_patch = args_model.environment_variable_patch\n            environment_variable_upserts: list[VariableBase] | None = None\n            deleted_environment_variable_ids: list[str] = []\n            if environment_variable_patch is not None:\n                environment_variable_upsert_mappings = Workflow.normalize_environment_variable_mappings(\n                    environment_variable_patch.environment_variables,\n                )\n                environment_variable_upserts = [\n                    variable_factory.build_environment_variable_from_mapping(obj)\n                    for obj in environment_variable_upsert_mappings\n                ]\n                deleted_environment_variable_ids = environment_variable_patch.deleted_environment_variable_ids\n            conversation_variables = [\n                variable_factory.build_conversation_variable_from_mapping(obj)\n                for obj in args_model.conversation_variables","sourceCodeStart":619,"sourceCodeEnd":655,"githubUrl":"https://github.com/langgenius/dify/blob/ef8544b173fd6cd7a8e71df2cab576e52bebbfbc/api/controllers/console/app/workflow.py#L619-L655","documentation":"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.'","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nfetch(url, { method: 'POST', body: formData })\n// after\nfetch(url, {\n  method: 'POST',\n  headers: { 'Content-Type': 'application/json' },\n  body: JSON.stringify(payload),\n})","handlingStrategy":"validation","validationCode":"ct = (headers or {}).get(\"Content-Type\", \"\")\nif \"application/json\" not in ct and \"text/plain\" not in ct:\n    raise ValueError(\"Content-Type must be application/json or text/plain\")\n# then ensure the body matches the chosen type","typeGuard":"def is_supported_workflow_content_type(value: str) -> bool:\n    v = (value or \"\").lower()\n    return \"application/json\" in v or \"text/plain\" in v","tryCatchPattern":"try:\n    resp = client.post(f\"/console/api/apps/{app_id}/workflows/draft\", headers=h, data=body)\nexcept HTTPError as err:\n    if err.response.status_code == 415:\n        raise TypeError(\"set Content-Type to application/json for the sync-draft endpoint\") from err\n    raise","preventionTips":["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."],"tags":["http-415","content-type","workflow","media-type","validation"],"backgroundTag":null,"analyzedSha":"ef8544b173fd6cd7a8e71df2cab576e52bebbfbc","analyzedAt":"2026-08-12T05:15:17.394Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}