Creates a workflow using Python or Ruby.

## Code sample

### C#


Before trying this sample, follow the C# setup instructions in the
[Workflows quickstart using
client libraries](https://docs.cloud.google.com/workflows/docs/quickstart-client-libraries).


For more information, see the
[Workflows C# API
reference documentation](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Workflows.V1/latest).


To authenticate to Workflows, set up Application Default Credentials.
For more information, see

[Set up authentication for a local development environment](https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment).

    using https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.ResourceNames.html;
    using https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Workflows.V1/latest/Google.Cloud.Workflows.V1.html;
    using https://docs.cloud.google.com/dotnet/docs/reference/Google.LongRunning/latest/Google.LongRunning.html;

    public sealed partial class GeneratedWorkflowsClientSnippets
    {
        /// <summary>Snippet for CreateWorkflow</summary>
        /// <remarks>
        /// This snippet has been automatically generated and should be regarded as a code template only.
        /// It will require modifications to work:
        /// - It may require correct/in-range values for request initialization.
        /// - It may require specifying regional endpoints when creating the service client as shown in
        ///   https://cloud.google.com/dotnet/docs/reference/help/client-configuration#endpoint.
        /// </remarks>
        public void CreateWorkflowRequestObject()
        {
            // Create client
            https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Workflows.V1/latest/Google.Cloud.Workflows.V1.WorkflowsClient.html workflowsClient = https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Workflows.V1/latest/Google.Cloud.Workflows.V1.WorkflowsClient.html.https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Workflows.V1/latest/Google.Cloud.Workflows.V1.WorkflowsClient.html#Google_Cloud_Workflows_V1_WorkflowsClient_Create();
            // Initialize request argument(s)
            https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Workflows.V1/latest/Google.Cloud.Workflows.V1.CreateWorkflowRequest.html request = new https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Workflows.V1/latest/Google.Cloud.Workflows.V1.CreateWorkflowRequest.html
            {
                ParentAsLocationName = https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.ResourceNames.LocationName.html.https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.ResourceNames.LocationName.html#Google_Api_Gax_ResourceNames_LocationName_FromProjectLocation_System_String_System_String_("[PROJECT]", "[LOCATION]"),
                Workflow = new Workflow(),
                WorkflowId = "",
            };
            // Make the request
            Operation<Workflow, OperationMetadata> response = workflowsClient.https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Workflows.V1/latest/Google.Cloud.Workflows.V1.WorkflowsClient.html#Google_Cloud_Workflows_V1_WorkflowsClient_CreateWorkflow_Google_Api_Gax_ResourceNames_LocationName_Google_Cloud_Workflows_V1_Workflow_System_String_Google_Api_Gax_Grpc_CallSettings_(request);

            // Poll until the returned long-running operation is complete
            Operation<Workflow, OperationMetadata> completedResponse = response.PollUntilCompleted();
            // Retrieve the operation result
            Workflow result = completedResponse.Result;

            // Or get the name of the operation
            string operationName = response.Name;
            // This name can be stored, then the long-running operation retrieved later by name
            Operation<Workflow, OperationMetadata> retrievedResponse = workflowsClient.https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Workflows.V1/latest/Google.Cloud.Workflows.V1.WorkflowsClient.html#Google_Cloud_Workflows_V1_WorkflowsClient_PollOnceCreateWorkflow_System_String_Google_Api_Gax_Grpc_CallSettings_(operationName);
            // Check if the retrieved long-running operation has completed
            if (retrievedResponse.IsCompleted)
            {
                // If it has completed, then access the result
                Workflow retrievedResult = retrievedResponse.Result;
            }
        }
    }

### Go


Before trying this sample, follow the Go setup instructions in the
[Workflows quickstart using
client libraries](https://docs.cloud.google.com/workflows/docs/quickstart-client-libraries).


For more information, see the
[Workflows Go API
reference documentation](https://godoc.org/cloud.google.com/go/workflows/apiv1beta).


To authenticate to Workflows, set up Application Default Credentials.
For more information, see

[Set up authentication for a local development environment](https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment).


    //go:build examples

    package main

    import (
    	"context"

    	workflows "cloud.google.com/go/workflows/apiv1"
    	workflowspb "cloud.google.com/go/workflows/apiv1/workflowspb"
    )

    func main() {
    	ctx := context.Background()
    	// This snippet has been automatically generated and should be regarded as a code template only.
    	// It will require modifications to work:
    	// - It may require correct/in-range values for request initialization.
    	// - It may require specifying regional endpoints when creating the service client as shown in:
    	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
    	c, err := workflows.https://docs.cloud.google.com/go/docs/reference/cloud.google.com/go/workflows/latest/apiv1.html#cloud_google_com_go_workflows_apiv1_Client_NewClient(ctx)
    	if err != nil {
    		// TODO: Handle error.
    	}
    	defer c.https://docs.cloud.google.com/go/docs/reference/cloud.google.com/go/workflows/latest/apiv1.html#cloud_google_com_go_workflows_apiv1_Client_Close()

    	req := &workflowspb.CreateWorkflowRequest{
    		// TODO: Fill request struct fields.
    		// See https://pkg.go.dev/cloud.google.com/go/workflows/apiv1/workflowspb#CreateWorkflowRequest.
    	}
    	op, err := c.CreateWorkflow(ctx, req)
    	if err != nil {
    		// TODO: Handle error.
    	}

    	resp, err := op.Wait(ctx)
    	if err != nil {
    		// TODO: Handle error.
    	}
    	// TODO: Use resp.
    	_ = resp
    }

### Java


Before trying this sample, follow the Java setup instructions in the
[Workflows quickstart using
client libraries](https://docs.cloud.google.com/workflows/docs/quickstart-client-libraries).


For more information, see the
[Workflows Java API
reference documentation](https://docs.cloud.google.com/java/docs/reference/google-cloud-workflows/latest/overview).


To authenticate to Workflows, set up Application Default Credentials.
For more information, see

[Set up authentication for a local development environment](https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment).

    import com.google.cloud.workflows.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-workflows/latest/com.google.cloud.workflows.v1.CreateWorkflowRequest.html;
    import com.google.cloud.workflows.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-workflows/latest/com.google.cloud.workflows.v1.LocationName.html;
    import com.google.cloud.workflows.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-workflows/latest/com.google.cloud.workflows.v1.Workflow.html;
    import com.google.cloud.workflows.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-workflows/latest/com.google.cloud.workflows.v1.WorkflowsClient.html;

    public class SyncCreateWorkflow {

      public static void main(String[] args) throws Exception {
        syncCreateWorkflow();
      }

      public static void syncCreateWorkflow() throws Exception {
        // This snippet has been automatically generated and should be regarded as a code template only.
        // It will require modifications to work:
        // - It may require correct/in-range values for request initialization.
        // - It may require specifying regional endpoints when creating the service client as shown in
        // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
        try (https://docs.cloud.google.com/java/docs/reference/google-cloud-workflows/latest/com.google.cloud.workflows.v1.WorkflowsClient.html workflowsClient = https://docs.cloud.google.com/java/docs/reference/google-cloud-workflows/latest/com.google.cloud.workflows.v1.WorkflowsClient.html.create()) {
          https://docs.cloud.google.com/java/docs/reference/google-cloud-workflows/latest/com.google.cloud.workflows.v1.CreateWorkflowRequest.html request =
              https://docs.cloud.google.com/java/docs/reference/google-cloud-workflows/latest/com.google.cloud.workflows.v1.CreateWorkflowRequest.html.newBuilder()
                  .setParent(https://docs.cloud.google.com/java/docs/reference/google-cloud-workflows/latest/com.google.cloud.workflows.v1.LocationName.html.of("[PROJECT]", "[LOCATION]").toString())
                  .setWorkflow(https://docs.cloud.google.com/java/docs/reference/google-cloud-workflows/latest/com.google.cloud.workflows.v1.Workflow.html.newBuilder().build())
                  .https://docs.cloud.google.com/java/docs/reference/google-cloud-workflows/latest/com.google.cloud.workflows.v1.CreateWorkflowRequest.Builder.html#com_google_cloud_workflows_v1_CreateWorkflowRequest_Builder_setWorkflowId_java_lang_String_("workflowId-360387270")
                  .build();
          https://docs.cloud.google.com/java/docs/reference/google-cloud-workflows/latest/com.google.cloud.workflows.v1.Workflow.html response = workflowsClient.https://docs.cloud.google.com/java/docs/reference/google-cloud-workflows/latest/com.google.cloud.workflows.v1.WorkflowsClient.html#com_google_cloud_workflows_v1_WorkflowsClient_createWorkflowAsync__org_jspecify_annotations_Nullable_com_google_cloud_workflows_v1_LocationName_com_google_cloud_workflows_v1_Workflow_java_lang_String_(request).get();
        }
      }
    }

### Python


Before trying this sample, follow the Python setup instructions in the
[Workflows quickstart using
client libraries](https://docs.cloud.google.com/workflows/docs/quickstart-client-libraries).


For more information, see the
[Workflows Python API
reference documentation](https://docs.cloud.google.com/python/docs/reference/workflows/latest).


To authenticate to Workflows, set up Application Default Credentials.
For more information, see

[Set up authentication for a local development environment](https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment).

    # This snippet has been automatically generated and should be regarded as a
    # code template only.
    # It will require modifications to work:
    # - It may require correct/in-range values for request initialization.
    # - It may require specifying regional endpoints when creating the service
    #   client as shown in:
    #   https://googleapis.dev/python/google-api-core/latest/client_options.html
    from google.cloud import https://docs.cloud.google.com/python/docs/reference/workflows/latest_v1


    def sample_create_workflow():
        # Create a client
        client = workflows_v1.https://docs.cloud.google.com/python/docs/reference/workflows/latest/google.cloud.workflows_v1.services.workflows.WorkflowsClient.html()

        # Initialize request argument(s)
        workflow = workflows_v1.https://docs.cloud.google.com/python/docs/reference/workflows/latest/google.cloud.workflows_v1.types.Workflow.html()
        workflow.source_contents = "source_contents_value"

        request = workflows_v1.https://docs.cloud.google.com/python/docs/reference/workflows/latest/google.cloud.workflows_v1.types.CreateWorkflowRequest.html(
            parent="parent_value",
            workflow=workflow,
            workflow_id="workflow_id_value",
        )

        # Make the request
        operation = client.https://docs.cloud.google.com/python/docs/reference/workflows/latest/google.cloud.workflows_v1.services.workflows.WorkflowsClient.html#google_cloud_workflows_v1_services_workflows_WorkflowsClient_create_workflow(request=request)

        print("Waiting for operation to complete...")

        response = operation.result()

        # Handle the response
        print(response)

### Ruby


Before trying this sample, follow the Ruby setup instructions in the
[Workflows quickstart using
client libraries](https://docs.cloud.google.com/workflows/docs/quickstart-client-libraries).


For more information, see the
[Workflows Ruby API
reference documentation](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-workflows/latest).


To authenticate to Workflows, set up Application Default Credentials.
For more information, see

[Set up authentication for a local development environment](https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment).

    require "google/cloud/workflows/v1"

    ##
    # Snippet for the create_workflow call in the Workflows service
    #
    # This snippet has been automatically generated and should be regarded as a code
    # template only. It will require modifications to work:
    # - It may require correct/in-range values for request initialization.
    # - It may require specifying regional endpoints when creating the service
    # client as shown in https://cloud.google.com/ruby/docs/reference.
    #
    # This is an auto-generated example demonstrating basic usage of
    # Google::Cloud::Workflows::V1::Workflows::Client#create_workflow.
    #
    def create_workflow
      # Create a client object. The client can be reused for multiple calls.
      client = Google::Cloud::Workflows::V1::Workflows::Client.new

      # Create a request. To set request fields, pass in keyword arguments.
      request = Google::Cloud::Workflows::V1::CreateWorkflowRequest.new

      # Call the create_workflow method.
      result = client.create_workflow request

      # The returned object is of type Gapic::Operation. You can use it to
      # check the status of an operation, cancel it, or wait for results.
      # Here is how to wait for a response.
      result.wait_until_done! timeout: 60
      if result.response?
        p result.response
      else
        puts "No response received."
      end
    end

## What's next


To search and filter code samples for other Google Cloud products, see the
[Google Cloud sample browser](https://docs.cloud.google.com/docs/samples?product=workflows).