Problem using dynamic JSON in HTTP Node

Hey, I want to use the HTTP node in n8n to access the model mistral-document-ai-2505.
This model is hosted and provided via Azure, and it uses different endpoints — you can only upload base64 strings.

So, I want to build a workflow that analyzes a document.
To do this, I use an “Execute Command” node to generate a base64 string from the file path.
This node works correctly and returns the following output:

[
  {
    "exitCode": 0,
    "stderr": "",
    "stdout": "JVBERi0xLjcNCiW1………tbW1DDAg"
  }
]

Now, when I try to configure the HTTP node, I’m stuck.
The model expects me to send a JSON body that looks like this:

{
  "model": "mistral-document-ai-2505",
  "document": {
    "type": "document_url",
    "document_url": "data:application/pdf;base64,JVBERi0xLjcNCiW1………tbW1DDAg"
  },
  "include_image_base64": "true"
}

When I use a static request, the node works perfectly.
But since I want to process multiple documents, I need to use the Base64 string from the previous node.
For that, I insert the variable from the previous node input, which results in:

{
  "model": "mistral-document-ai-2505",
  "document": {
    "type": "document_url",
    "document_url": "data:application/pdf;base64,{{$json.stdout}}"
  },
  "include_image_base64": "true"
}

In the preview/output panel, the variable is correctly resolved — it shows the proper Base64 string, highlighted in green.
However, when I actually execute the node, I get the following error message:

“JSON parameter needs to be valid JSON”

I suspect the issue occurs during the variable substitution — something goes wrong when n8n converts the variable into JSON format.

Here’s how my HTTP node is configured:

  • “Send Body” is enabled

  • Body Content Type = JSON

  • The JSON code is in the “JSON” field

  • I use “Fixed” for the static version, and “Expression” for the dynamic one

I’d really appreciate any help or solution for this.

Thanks!

Node type: n8n-nodes-base.httpRequest
Node version: 4.2 (Latest)
n8n version: 1.109.2 (Self-hosted)
Stack trace:
NodeOperationError: JSON parameter needs to be valid JSON at ExecuteContext.execute

Hi @Clemens
Everything looks fine to me,
If possible, could you please share an example workflow or a screenshot of the exact error in the node?

Hey mohamed3nan,

please excuse my delayed response, I’ve been sick.

For some inexplicable reason, it’s working now.

Attached is the solution for documentation in the forum:

Workflow:

„Read/ Write Files from Disk“ –> „Extract from File“ –> „HTTP Request“

„Read/ Write Files from Disk“

Description: Loads the file from memory

„Extract from File“

Description: Converts the file into a Base64 string

Node: „HTTP Request“

Description: Sends an HTTP request to Azure Mistral OCR (Model: mistral-document-ai-2505)

Code:

{

“model”: “mistral-document-ai-2505”,

“document”: {

"type": "document_url",

"document_url": "data:application/pdf;base64,{{ $json.data }}"

},

“include_image_base64”: “true”

}

Many thanks to all the helpers!
Best regards,
Clemens

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.