Conditional logic for http request

Describe the problem/error/question

Im using responses from a google form to create a jira issue, i.e IT support tickets etc.

I want to implement conditional logic , i.e if option A is selected then pass the value of option A to http request.

I tried looking into switch nodes but when I using expressions in the http raw body it seems to be static and not dynamic as I thought. i,e when I load data using option b, option A is still in the raw body.

What am I doing wrong?

What is the error message (if any)?

Please share your workflow

Share the output returned by the last node

Information on your n8n setup

  • **n8n version:Latest
  • Running n8n via Docker:
  • **Operating system:Mac

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:
  • **n8n version:lastest
  • Database (default: SQLite): Default
  • n8n EXECUTIONS_PROCESS setting (default: own, main): default
  • **Running n8n via (Docker, npm, n8n cloud, desktop app):docker
  • **Operating system:MacOs Sonoma

To use expressions you need to set them as “Expression” on the top right of the field.

Can you just directly pass in the value from the webhook to the http request?
If the value is the same thing then you can do that. It would be something like this.

If you need to change the value for the http request, for example if the input is b but you need to output 2, then there are a few options.

Code would probably be easiest for anyone comfortable with that.

You could also use a switch statement, but you will need to manually set the fields as switch statements, like if statements, don’t change values just control the flow

If there are only two options, you could also use a ternary operator in the expression

{{ $json.option === 'a' ? '1' : '2' }}

With this code, if $json.option === 'a' is true, it will set the value to 1. Otherwise it will be 2

I hope this is helpful. If not please send a sample of the webhook body then i can help further


Thanks for replying.

I don’t need to change the values.

I would assume I could pass the value straight to http request raw body using expressions. I have tried expressions using {{$json.body[‘what team’]}} into the json raw body.

However, when I test with option1 value and then test a submission with option2 its like option1 has been hardcoded into the json raw body that I wish to send.

You can pass them right into the body. Are you sure the fields are set as expression? See the image below

Screenshot 2024-02-18 at 4.30.13 PM

If that doesnt help then please include some sample json for me to look at to help further


Its working correctly now, just a oversight on my end.

Thanks for the support @liam