I’m trying to pass an object(like below) as a POST request body param, I’m unable to do so, would someone be able to help me here?
{'CartItem': {'GroupId': Group, 'quantity': quantity}}
I’m trying to pass an object(like below) as a POST request body param, I’m unable to do so, would someone be able to help me here?
{'CartItem': {'GroupId': Group, 'quantity': quantity}}
Hi @nixonsam, first of all welcome to the community ![]()
You should be able to pass on any JSON structure when enabling the JSON/RAW Parameters option of the HTTP Request node (I assume that’s the one you have in mind):
You can then add any valid JSON object in the Body Parameters field:
{"CartItem": {"GroupId": "Foo", "quantity": 123}}
This would also work for lists of multiple items like so:
[{"CartItem": {"GroupId": "Foo", "quantity": 123}},
{"CartItem": {"GroupId": "Bar", "quantity": 456}}]
Is this what you were looking for? If not, could you share a link to the documentation of the API you are calling?
@MutedJam Thanks a lot for your help! It worked, however, I’m getting a different error now:
ERROR: Cannot create property 'accept' on string '{'Content-Type': 'application/json', 'Accept': 'application/json'}'
defining the header like below solved it
{{ {'Content-Type': 'application/json', 'Accept': 'application/json'} }}
Awesome, glad to hear you figured it out, thanks so much for confirming!
For illustration purposes. The working configuration with JSON format used for both headers and body mentioned in this discussion (in line with latest n8n version). However, when using expressions (especially when taking values from previous nodes) this could become trickier depending on the complexity of JSON itself. Also configuration could depend on the API requirements. What works for one might not work for the other.