# SubFlows

SubFlow in cosmocloud provides modular approach to build reusable piece of flow. It helps you to build a piece of code once and plug it in existing flow.

## Create SubFlow

* Navigate to **Application Layer -> SubFlows** in your Cosmocloud project.
* Click on **Create SubFlow** button
* Add your SubFlow name as well as add the **Arguments** your SubFlow will receive from the calling Flow (an API or other SubFlow).

## Understanding Arguments

<figure><img src="https://392607133-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZCdm9aJ8vkvDIIbg04AL%2Fuploads%2FMWvco8lzcLeb0WyqQUgX%2Fargs.png?alt=media&#x26;token=ab6cf0e7-9b7d-4b59-8786-53dbc99c21d4" alt=""><figcaption></figcaption></figure>

* **Toggle :** This is used to mark if argument is `required` or `optional`
* **Argument key :** argument name to be received
* **Argument type :** It specify what type of value is expected
* **Default :** It specify default value if user didn't enter value. (optional)

## How to use SubFlow

SubFlow in cosmocloud is an isolated component which means  every value that you want to access in SubFlow needs to passed as an argument.

#### Understanding SubFlow node

* To execute this SubFlow in an existing API, you can use `Execute SubFlow` node&#x20;

<figure><img src="https://392607133-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZCdm9aJ8vkvDIIbg04AL%2Fuploads%2FVytERDhIXJVuN3qLO4xM%2Fsubflow1.png?alt=media&#x26;token=b2b4df1a-bb9c-49f0-b89c-c521d64c6a0e" alt=""><figcaption></figcaption></figure>

* You need to select the SubFlow which you need to execute and also pass required arguments.

<figure><img src="https://392607133-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZCdm9aJ8vkvDIIbg04AL%2Fuploads%2FwJS4nuvN9bthKArIYDOl%2Fsubflow2.png?alt=media&#x26;token=bbbea57b-6c2f-4202-bcfd-2eae5b24e2c2" alt=""><figcaption></figcaption></figure>

* Arguments will be passed in as keys and values. These values are case sensitive so make sure enter correct terms.

<figure><img src="https://392607133-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZCdm9aJ8vkvDIIbg04AL%2Fuploads%2FnTUiK3ZnQCk4nkpHLBtN%2Fsubfl.png?alt=media&#x26;token=1a3bb8ba-b796-459c-b2de-5fe22b5da796" alt=""><figcaption></figcaption></figure>
