# Flow Builder - Building Conditional Logics

## Utilising If/Else Node

In many scenarios, you need to execute specific instructions based on certain conditions. This is where If/Else nodes become crucial in Cosmocloud's flow builder.   &#x20;

Imagine you are building an API that determines user eligibility for a promotional offer based on their age. Here’s how you can implement this using If/Else node:

1. Select the If Else node.

<figure><img src="https://lh7-us.googleusercontent.com/docsz/AD_4nXfHYDDtqnmktYI10cWWgeLaQcLBaaNBDCN1PKbx9m-fnf2GpnYDDr5ZSvTTxjUBNWHgqlPn_ziDDu7SuoBoDB2RH2-OEwDUtKAohePtTar4gejyGh1kJfV9XNvkuU4_8yllu1QSnaTn4kJh4NyQH6WPqs4?key=3g19iCAD9aT3BbvyxuQRkw" alt=""><figcaption></figcaption></figure>

2. Click on the node to go to the properties panel of the node and click on edit condition to add the condition criteria for our If Else node. In our case, the criteria is to check whether the age of the user is greater than or equal to 18 or not.

<figure><img src="https://lh7-us.googleusercontent.com/docsz/AD_4nXd5aIKV1z4wznoDGx12AXutjZ5vt_gp8brWX2UV4iSaGohY7xxzKw2oUrH-OXfrKlbzHI-HF8EmtA8lMxB79SF2AnE6Wcyb_Ie3LigoBZ-vN0f5UFZv-qXdMFxGKT2Fd0t6lu6fjRrLFAoX0qUYUaHVbIMg?key=3g19iCAD9aT3BbvyxuQRkw" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
For creating more complex conditions, you can check [building conditions](https://docs.cosmocloud.io/flow-builder/cql-cosmocloud-query-language/building-conditions).
{% endhint %}

3. Now, we can see a True branch and a False branch coming out of the node.&#x20;

<figure><img src="https://lh7-us.googleusercontent.com/docsz/AD_4nXc4XvWJQndJHJAxInEAtzOKClOkyF2R7OuzpgH_-bN3RhR6wHyllBjanWgJay-x3CSDBRKWR-CNBBmIPLjuKSdIseZfkvABBueuZRhs0Xu3P7Jl7NV0oUsJWJ8RBAXv0A5MMNGE50Fh_nWRmxTqupvFErk?key=3g19iCAD9aT3BbvyxuQRkw" alt=""><figcaption></figcaption></figure>

4. **TRUE Path:** If age is greater than 18, proceed to offer eligibility logic.
5. **FALSE Path:**&#x49;f age is 18 or less, send a response indicating the user is not eligible for the offer.

To learn more about the If/else node [click here](https://docs.cosmocloud.io/flow-builder/node-types/conditional-nodes/if-else).

## API with Switch Case Node

In many scenarios, you need to execute different sets of instructions based on the value of a specific variable. This is where SWITCH/CASE nodes become crucial in Cosmocloud's flow builder.

Imagine you are building an API that processes different types of customer service requests. Here’s how you can implement this using SWITCH/CASE nodes:

1. Let's assume you are sending a `type` field through the query parameters and you want to execute different flows depending on the `type`.
2. First, select the switch case node and add it to your flow.

<figure><img src="https://lh7-us.googleusercontent.com/docsz/AD_4nXc9ilN8fMPZ7iCjpRkYwFVi_QaRfHauJbrjrJwzHs75YG2y3SfUreJhJYmCS1DXYBSrdMv_n8Y81h_Ww4GrKAHJkee5dq0OaxjYM10IaZ6bqVLEyBSMXbRR7aq9xNeC0K_3LX_DTloM66lKxpFXsMxi3lzr?key=3g19iCAD9aT3BbvyxuQRkw" alt=""><figcaption></figcaption></figure>

3. Now, configure the node as follows:

<figure><img src="https://lh7-us.googleusercontent.com/docsz/AD_4nXfAoPZjRnoHbhb8jj8A3EIDjFsUJNBBwvEXQ2KbG-QWY7vPCxzPtOkTWyMt-lzVbS325SA95bBeGPt60jcZnJJT-g-abs8uAIE9X0WIwla9wWP9zuxDqVgovWg7qF6nCsGStfU6nlbA6cGyqF_xIRhe_duH?key=3g19iCAD9aT3BbvyxuQRkw" alt=""><figcaption></figcaption></figure>

4. You now have 4 branches labelled as `billing`, `technical`, `account_management` and `default`. Here's how the flow looks now:

<figure><img src="https://lh7-us.googleusercontent.com/docsz/AD_4nXcLKwNpszW62m6cmQ85blOaBPTqShIFS0VITtx-CwFcgPecza8Arj_e3f7CN3PoeL0aAKsnUluut-xWjTXB1hFXpxTRZR3aM8i_BHzgEU5a0Q339aivEFz2nLzIlwC5-mLBY5lDJaVOU_Qo05kBbTT--boX?key=3g19iCAD9aT3BbvyxuQRkw" alt=""><figcaption></figcaption></figure>

5. Now let's return a unique response for each type of request i.e., if the type in the query parameters is `billing` we execute the billing branch and return `You are in the billing branch` as the response.
6. Similarly , add a unique response for other branches as well. This is how the flow looks like:

![](https://lh7-us.googleusercontent.com/docsz/AD_4nXdDyi01eZ0VDWozqiOCn60QMNEs32_SJN9pfsQaUXf3M-i6i3DQLbaaUhMwkljkQP4WEItpQOk2hjhtqHqL6Lbyn9cS58uv7AUIUeSILG7J1zdU5q6kZu1lTCLHocuyes827vCTP_38Jz_xTdOArKiUFkw3?key=3g19iCAD9aT3BbvyxuQRkw)

7. Now let's test this API.

<figure><img src="https://lh7-us.googleusercontent.com/docsz/AD_4nXdAlMTAbLomAjj9mOK0kXx0VO67qo2HfG4JvtMRCflhZ0_aKOGkn2AY44zx2sL9mMsgDecRhM0Isj8I-dKq9epMqDbgy7PKvknwPrGDRi1hXWX3QzCZNBG2pPbkx1XCApoD-rebSA1FxDxC0P7uCHX_StXC?key=3g19iCAD9aT3BbvyxuQRkw" alt=""><figcaption></figcaption></figure>

<figure><img src="https://lh7-us.googleusercontent.com/docsz/AD_4nXc3jPbniv44SJGpGPZVQOY7rdD6YpBj8vV07nUXQ7QjF2itXhbSzVfO5eMIIdbg9AegLQv5R10CBeGhD3E6oqRVvTDXv5_dZUofPP6kvL12_VNhP0g8VpZ07Hzo9RlWw4-5gvunSB8OOapzdf-9IEG52sgl?key=3g19iCAD9aT3BbvyxuQRkw" alt=""><figcaption></figcaption></figure>

<figure><img src="https://lh7-us.googleusercontent.com/docsz/AD_4nXfHR67ySSSXbBVYtF67tcBE8N8gzf_dIrutos3SqN-ajrPBB5g-duwPCBbHcxWH8vqBGGEQeud7CjqfOKHTA6VWrwnewcvO8xwRryVxJWfTBpHNI21nmET67Ees6PaEw1A4B92P4plY8CgTkFplN-a3-ox3?key=3g19iCAD9aT3BbvyxuQRkw" alt=""><figcaption></figcaption></figure>

To learn more about the Switch Case node [click here](https://docs.cosmocloud.io/flow-builder/node-types/conditional-nodes/switch-case)

<br>

<br>
