All Workflows code samples

This page contains code samples for Workflows. To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.

Assign variables

Assigns string and number values to variables. Variable assignments are executed sequentially.

View in documentation

Calculate math floor

After receiving an HTTP request, extracts input from the JSON body, calculates its math.floor, and returns the result.

Catch errors

Implements a custom exception handler based on the HTTP status code returned by a GET request. The workflow catches a potential exception and returns a predefined error message.

View in documentation

Conditional jump to a specific step

Jumps to a specific step depending on the value returned by the first step of the workflow.

View in documentation

Conditional jump to a specific step

Jumps to a specific step depending on the day of the week returned by the first step of the workflow.

View in documentation

Connector for BigQuery

Workflows connector that defines the built-in function used to access BigQuery within a workflow.

View in documentation

Connector for Cloud Build

Workflows connector that defines the built-in function used to access Cloud Build within a workflow.

View in documentation

Connector for Cloud Functions

Workflows connector that defines the built-in function used to access Cloud Functions within a workflow.

Connector for Cloud Natural Language

Workflows connector that defines the built-in function used to access Cloud Natural Language within a workflow.

Connector for Cloud Run

Workflows connector that defines the built-in function used to access Cloud Run within a workflow.

Connector for Cloud Scheduler

Workflows connector that defines the built-in function used to access Cloud Scheduler within a workflow.

Connector for Cloud Spanner

Workflows connector that defines the built-in function used to access Cloud Spanner within a workflow.

View in documentation

Connector for Cloud SQL Admin

Workflows connector that defines the built-in function used to access Cloud SQL Admin within a workflow.

Connector for Cloud Storage

Workflows connector that defines the built-in function used to access Cloud Storage within a workflow.

Connector for Cloud Tasks

Workflows connector that defines the built-in function used to access Cloud Tasks within a workflow.

View in documentation

Connector for Cloud Translation

Workflows connector that defines the built-in function used to access Cloud Translation within a workflow.

Connector for Compute Engine

Workflows connector that defines the built-in function used to access Compute Engine within a workflow.

Connector for Dataflow

Workflows connector that defines the built-in function used to access Dataflow within a workflow.

View in documentation

Connector for Document AI

Workflows connector that defines the built-in function used to access Document AI within a workflow.

Connector for Firestore

Workflows connector that defines the built-in function used to access Firestore within a workflow.

Connector for Firestore (read)

Reads from Firestore using a Workflows connector.

Connector for Firestore (write)

Writes to Firestore using a Workflows connector.

Connector for Kubernetes Engine container

Workflows connector that defines the built-in function used to access a Kubernetes Engine container within a workflow.

Connector for Pub/Sub

Workflows connector that defines the built-in function used to access Pub/Sub within a workflow.

View in documentation

Connector for Secret Manager

Workflows connector that defines the built-in function used to access Secret Manager within a workflow.

Connector for Storage Transfer Service

Workflows connector that defines the built-in function used to access Storage Transfer Service within a workflow.

Connector for Workflows definitions

Workflows connector that defines the built-in function used to access Workflows definitions.

View in documentation

Connector for Workflows executions

Workflows connector that defines the built-in function used to access Workflows executions.

Create a workflow

Creates a workflow.

Create a workflow using Ruby

Creates a workflow using Ruby.

Define a map

Defines a map (dictionary) that can hold a user-defined structure of variables or lists.

Define lists

Defines a few lists.

View in documentation

Delete a workflow

Deletes a workflow.

Delete a workflow using Ruby

Deletes a workflow using Ruby.

Explicitly step to the next workflow step

Uses the next: command to explicitly define the sequence of workflow steps and executes steps in a different order than they appear in the workflow definition.

View in documentation

Generate a random number and return result in JSON

After receiving an HTTP request, this function generates a random number between 1 and 100, and then returns the number in JSON format.

Get a workflow

Gets a workflow.

Get a workflow using Ruby

Gets a workflow using Ruby.

Handle errors with custom predicate

Defines a custom error handler, including a custom predicate and custom backoff parameters.

View in documentation

Implicitly step to the next workflow step

Executes the steps of a workflow in the order that they appear in the workflow definition.

View in documentation

Invoke a Cloud Run workload that requires authentication

Makes an authenticated request within a workflow, using OpenID Connect (OIDC) to connect with Cloud Run.

Iterate through a list

Uses a combination of conditional jumps, variables, and the len() function to iterate through a list.

View in documentation

List workflows

Lists workflows.

List workflows using Ruby

Lists workflows using Ruby.

Make a call to a sample API

Makes a call to a sample API. The returned day of the week is passed to the Wikipedia API. Relevant articles on Wikipedia about the current day of the week are returned.

Make an external HTTP GET request with headers

Makes an HTTP GET request with a custom header.

View in documentation

Make an external HTTP POST request

Makes a POST request to an external HTTP endpoint.

View in documentation

Multiply by 2 and return result in JSON

After receiving an HTTP request, this function extracts the input from the JSON body, multiplies it by 2, and returns the result in JSON format.

Retry after an HTTP 500 error

Implements a custom retry policy that retries HTTP requests that have returned an HTTP 500 status code.

View in documentation

Retry steps using a default retry policy

Uses a built-in retry policy for HTTP requests.

View in documentation

Retry steps with custom configuration

Uses a standard retry predicate that determines when to perform a retry, and a custom maximum number of retries and backoff parameters.

View in documentation

Stop a Compute Engine instance through an HTTP request

Makes an authenticated request within a workflow, using OAuth 2.0 to stop a Compute Engine instance.

Translate text using the Cloud Translation API

Makes an HTTP POST request to the Cloud Translation API to translate text from English to Russian.

Update a workflow

Updates a workflow.

Update a workflow using Ruby

Updates a workflow using Ruby.

Use a simple subworkflow

Implements a simple subworkflow that is defined after the main workflow definition.

View in documentation

Use an embedded switch statement to execute steps

Uses a switch structure to directly execute steps when a condition is met, without jumping to other steps.

View in documentation

Use an expression to assign a variable value

Uses an expression to assign the value of a variable previously defined.

View in documentation

Use arguments in a workflow

Accesses runtime arguments passed to the workflow as part of the execution request and declared as a parameter of the main workflow.

Use client libraries to execute a workflow

Use client libraries to execute a workflow. Polls the workflow's execution using exponential backoff until the execution terminates and then prints the results.

Use OIDC to authenticate when making a request to Cloud Functions

Makes an HTTP request using OIDC by adding an auth section to the args section of the workflow's definition, after specifying the URL.

View in documentation

Write to Firestore through an HTTP request

Makes an authenticated request within a workflow, using OAuth 2.0 to write to Firestore.