Create a new Eventarc pipeline with an HTTP endpoint destination.

## Code sample

### Go


To authenticate to Eventarc, 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.md.txt).

```go

import (
	"context"
	"fmt"
	"io"

	eventarc "cloud.google.com/go/eventarc/apiv1"
	"cloud.google.com/go/eventarc/apiv1/eventarcpb"
)

// Use the CreatePipeline method.
func createPipeline(ctx context.Context, w io.Writer, pipelineID string, projectID string, locationID string) error {
	parent := fmt.Sprintf("projects/%s/locations/%s", projectID, locationID)

	destination := &eventarcpb.Pipeline_Destination{
		DestinationDescriptor: &eventarcpb.Pipeline_Destination_HttpEndpoint_{
			HttpEndpoint: &eventarcpb.Pipeline_Destination_HttpEndpoint{
				Uri: "https://example.com",
			},
		},
	}

	pipeline := &eventarcpb.Pipeline{
		Destinations: []*eventarcpb.Pipeline_Destination{destination},
	}

	client, err := eventarc.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("NewClient failed: %w", err)
	}
	defer client.Close()

	req := &eventarcpb.CreatePipelineRequest{
		Parent:     parent,
		Pipeline:   pipeline,
		PipelineId: pipelineID,
	}

	op, err := client.CreatePipeline(ctx, req)
	if err != nil {
		return fmt.Errorf("CreatePipeline failed: %w", err)
	}

	resp, err := op.Wait(ctx)
	if err != nil {
		return fmt.Errorf("Wait failed: %w", err)
	}

	fmt.Fprintf(w, "Created pipeline: %s\n", resp.GetName())

	return nil
}
```

### Node.js


To authenticate to Eventarc, 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.md.txt).

```javascript
'use strict';

const {EventarcClient} = require('@google-cloud/eventarc');
const {status} = require('@grpc/grpc-js');

const client = new EventarcClient();

/**
 * Creates an Eventarc pipeline.
 *
 * @param {string} pipelineId - The user-provided ID to be assigned to the pipeline (for example, 'example-pipeline').
 * @param {string} projectId - The Google Cloud project ID.
 * @param {string} locationId - The location ID (for example, 'us-central1').
 */
async function createPipeline(pipelineId, projectId, locationId) {
  try {
    const parent = `projects/${projectId}/locations/${locationId}`;
    const pipeline = {
      destinations: [
        {
          httpEndpoint: {
            uri: 'https://example.com',
          },
        },
      ],
    };

    const [operation] = await client.createPipeline({
      parent,
      pipeline,
      pipelineId,
    });

    // Wait for the long-running operation to complete.
    const [response] = await operation.promise();

    console.log(`Created pipeline: ${response.name}`);
  } catch (err) {
    if (err.code === status.ALREADY_EXISTS) {
      console.error(`Pipeline already exists: ${err.message}`);
    } else if (err.code === status.INVALID_ARGUMENT) {
      console.error(`Invalid argument provided: ${err.message}`);
    } else {
      console.error(`Failed to create pipeline: ${err.message}`);
    }
    throw err;
  }
}

module.exports = { createPipeline };
```

### Python


To authenticate to Eventarc, 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.md.txt).

```python
import google.api_core.exceptions
from google.cloud import eventarc_v1

client = eventarc_v1.EventarcClient()


def create_pipeline(pipeline_id: str, project_id: str, location_id: str) -> None:
    """Use the create_pipeline method

    Args:
        pipeline_id: The identifier to assign to the pipeline (for example, 'example-pipeline').
        project_id: The Google Cloud project ID.
        location_id: The Google Cloud location ID (for example, 'us-central1').
    """
    parent = f"projects/{project_id}/locations/{location_id}"

    endpoint = eventarc_v1.Pipeline.Destination.HttpEndpoint(
        uri="https://example.com/events"
    )
    destination = eventarc_v1.Pipeline.Destination(http_endpoint=endpoint)
    pipeline = eventarc_v1.Pipeline(destinations=[destination])

    try:
        operation = client.create_pipeline(
            parent=parent,
            pipeline=pipeline,
            pipeline_id=pipeline_id,
        )
        response = operation.result()
        print(f"Created pipeline: {response.name}")
    except google.api_core.exceptions.GoogleAPICallError as error:
        print(f"Failed to create pipeline: {error}")
```

## 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.md.txt?product=eventarc).