To create a workflow, you define the steps you want and their order of execution
using the Workflows syntax. Every workflow must have at least one step.

By default, Workflows treats steps as if they are in an ordered
list and executes them one at a time until all the steps have run. For example,
this workflow has two steps:

### YAML

```yaml
  - STEP_NAME_A:
      ...
  - STEP_NAME_B:
      ...
  
```

### JSON

```json
  [
    {
      "STEP_NAME_A": {
        ...
      }
    },
    {
      "STEP_NAME_B": {
        ...
      }
    },
  ]
    
```

## Step names

Step names must be unique at the
[subworkflow](https://docs.cloud.google.com/workflows/docs/reference/syntax/subworkflows) level. For example,
in the following workflow, a step named `init` is allowed in both the `main`
block and the subworkflow.

### YAML

```yaml
main:
    params: [input]
    steps:
    - init:
        call: sub
sub:
    steps:
    - init:
        assign:
          - a: 0
```

### JSON

```json
{
  "main": {
    "params": [
      "input"
    ],
    "steps": [
      {
        "init": {
          "call": "sub"
        }
      }
    ]
  },
  "sub": {
    "steps": [
      {
        "init": {
          "assign": [
            {
              "a": 0
            }
          ]
        }
      }
    ]
  }
}
```

Workflows doesn't enforce a naming convention for step names.
However, we recommend consistent usage such as creating step names that only
include alphanumeric characters and underscores.

## Step types

Workflows supports various types of steps, including the following:

- [Assign a variable](https://docs.cloud.google.com/workflows/docs/reference/syntax/variables)
- [Apply conditions](https://docs.cloud.google.com/workflows/docs/reference/syntax/conditions)
- [Invoke an HTTP endpoint](https://docs.cloud.google.com/workflows/docs/http-requests)
- [Execute workflow steps in parallel](https://docs.cloud.google.com/workflows/docs/execute-parallel-steps)
- [Return a value](https://docs.cloud.google.com/workflows/docs/reference/syntax/calls)
- [Pause a workflow](https://docs.cloud.google.com/workflows/docs/sleeping)

## Implicit step ordering

This sample shows implicit step ordering within a workflow. By default, the
steps of a workflow are executed in the order they appear in the workflow
definition.

### YAML

    - first_step:
        call: http.get
        args:
          url: https://www.example.com/callA
    - second_step:
        call: http.get
        args:
          url: https://www.example.com/callB
    - third_step:
        call: http.get
        args:
          url: https://www.example.com/callC

### JSON

    [
      {
        "first_step": {
          "call": "http.get",
          "args": {
            "url": "https://www.example.com/callA"
          }
        }
      },
      {
        "second_step": {
          "call": "http.get",
          "args": {
            "url": "https://www.example.com/callB"
          }
        }
      },
      {
        "third_step": {
          "call": "http.get",
          "args": {
            "url": "https://www.example.com/callC"
          }
        }
      }
    ]

## Nested steps

You can use a `steps` block to nest a series of steps and further define a
workflow:

### YAML

```yaml
  - STEP_NAME:
    steps:
      - STEP_NAME_1:
          steps:
              - STEP_NAME_A:
                  ...
              - STEP_NAME_B:
                  ...
      - STEP_NAME_2:
          steps:
              - STEP_NAME_C:
                  ...
  
```

### JSON

```json
    {
      STEP_NAME: {
      "steps": [
        {
          STEP_NAME_1: {
            "steps": [
              {
                STEP_NAME_A:
                  ...
              },
              {
                STEP_NAME_B:
                  ...
              }
            ]
          }
        },
        {
          STEP_NAME_2: {
            "steps": [
              {
                STEP_NAME_C:
                  ...
              }
            ]
          }
        }
      ]
    }
  }
    
```

Variables declared in a `steps` block have workflow-level scope and can be
accessed outside of the block. Any step type can be nested inside of a `steps`
block including `assign`, `call`, and `switch`. For example:

### YAML

```yaml
  main:
      steps:
      - series_one:
          steps:
              - step_a:
                  call: http.get
                  args:
                      url: https://host.com/api1
                  result: api_response1
              - step_b:
                  assign:
                      - varA: "Monday"
                      - varB: "Tuesday"
      - series_two:
          steps:
              - step_c:
                  call: http.get
                  args:
                      url: https://host.com/api2
                  result: api_response2
              - step_d:
                  assign:
                      - varC: "Wednesday"
                      - varD: "Thursday"
  
```

### JSON

```json
  {
    "main": {
      "steps": [
        {
          "series_one": {
            "steps": [
              {
                "step_a": {
                  "call": "http.get",
                  "args": {
                    "url": "https://host.com/api1"
                  },
                  "result": "api_response1"
                }
              },
              {
                "step_b": {
                  "assign": [
                    {
                      "varA": "Monday"
                    },
                    {
                      "varB": "Tuesday"
                    }
                  ]
                }
              }
            ]
          }
        },
        {
          "series_two": {
            "steps": [
              {
                "step_c": {
                  "call": "http.get",
                  "args": {
                    "url": "https://host.com/api2"
                  },
                  "result": "api_response2"
                }
              },
              {
                "step_d": {
                  "assign": [
                    {
                      "varC": "Wednesday"
                    },
                    {
                      "varD": "Thursday"
                    }
                  ]
                }
              }
            ]
          }
        }
      ]
    }
  }
    
```

Note that in some cases, `steps` is required; for example, when defining a
[subworkflow](https://docs.cloud.google.com/workflows/docs/reference/syntax/subworkflows) or a [for loop](https://docs.cloud.google.com/workflows/docs/reference/syntax/iteration).