How to pass the result of previous node as it is on the body of a HTTP Request node?

Describe the question

I’m walking around this expresión used in an HTTP Request body (JSON)

"items": {{ $json.items }},
"contactCode": "{{ $json["contactCode"] }}",
"currency": "{{ $json["currency"] }}",
"date": "{{ $json["date"] }}",
"desc": "{{ $json["desc"] }}",
"paymentMethodId": "{{ $json["paymentMethodId"] }}",
"salesChannel": {{ $json["salesChannel"] }}

In the expresion box I see all fine, however, I’m getting an error because I think there is something not arriving properly to destination:

Instead of this:

Any help on how to solve it?

Hi @MaaPer, in your expression you are mixing a regular string (even though it looks like JSON) with actual JSON objects. When mixing such elements, JavaScript would use the default string representation of a JSON object which is the dreaded [object Object].

You can avoid this by returning a single JSON object and nothing else. Simply make sure you are wrapping your entire expression in {{ and }} (which marks the beginning and end of JavaScript code in n8n).

In your example something like this should do the job:

{{ {
  "items": $json.items,
  "contactCode": $json["contactCode"],
  "currency": $json["currency"],
  "date": $json["date"],
  "desc": $json["desc"],
  "paymentMethodId": $json["paymentMethodId"],
  "salesChannel": $json["salesChannel"]
} }}

Make sure to not have any white space at the beginning or end of your field. If you are using an older version of n8n you might need to write this expression in a single line.

Perhaps you can give this a go on your end and let me know if this works for you?

1 Like

Awesome, thanks for the support!!

1 Like

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