# Connect source to your GCP project

Connects a Google Cloud project to an existing `gcp` source, so we can discover metrics, manage log sinks, and enrich your Google Cloud resources.

This is the API equivalent of the **Connect your GCP project** step in the source's Ingest tab.

Create the source first with [Create a source](https://betterstack.com/docs/logs/api/create-a-source/) and `"platform": "gcp"`, deploy the Google Cloud components as described in [Google Cloud](https://betterstack.com/docs/logs/google-cloud/), then send the project ID and project number back with the request below.

[info]
#### Where do the project ID and number come from?
Both are produced by the Better Stack setup script and by the Terraform module, which output `project_id` and `project_number`. In the Google Cloud console you find them on the project's dashboard, or with `gcloud projects describe PROJECT_ID`.
[/info]

[endpoint]
base_url = "https://telemetry.betterstack.com"
path = "/api/v1/sources/{source_id}"
method = "PATCH"

[[path_param]]
name = "id"
description = "ID of the `gcp` source you want to connect the project to"
required = true
type = "string"

[[body_param]]
name = "gcp_project_id"
description = """
The Google Cloud project ID, for example `my-gcp-project`.  \nMust be sent together with `gcp_project_number`.
"""
required = false
type = "string"

[[body_param]]
name = "gcp_project_number"
description = """
The Google Cloud project number, for example `587153488274`.  \nMust be sent together with `gcp_project_id`.
"""
required = false
type = "string"

[[body_param]]
name = "gcp_account_id"
description = "The ID of a Google Cloud project you have already connected. Send this instead of `gcp_project_id` and `gcp_project_number` to link the source to that project."
required = false
type = "string"

[[header]]
name = "Authorization"
description = "Bearer `$TOKEN`"
required = true
type = "string"
[/endpoint]

[responses]
[[response]]
status = 200
description = '''The Google Cloud project was connected. The credentials are write-only and are never returned, so the response is the plain source object.'''
body = '''{
    "data": {
        "id": "96",
        "type": "source",
        "attributes": {
            "source_group_id": 573,
            "team_id": 123,
            "team_name": "Test team",
            "name": "GCP production",
            "platform": "gcp",
            "table_name": "gcp_production",
            "token": "FczKcxEhjEDE58dBX7XaeX1q",
            "ingesting_paused": false,
            "ingesting_host": "s96.eu-nbg-2.betterstackdata.com",
            "created_at": "2026-05-27T12:30:41.695Z",
            "updated_at": "2026-06-11T14:00:50.756Z",
            "logs_retention": 7,
            "metrics_retention": 14,
            "data_region": "eu-nbg-2"
        }
    }
}'''

[[response]]
status = 404
description = '''Your team has no source with the given ID'''
body = '''{
    "errors": "Resource with provided ID was not found"
}'''

[[response]]
status = 422
description = '''Only one of the two values was sent'''
body = '''{
    "errors": "Both Project ID and Project Number are required.",
    "invalid_attributes": []
}'''

[[response]]
status = 422
description = '''Better Stack could not access the project with Workload Identity Federation'''
body = '''{
    "errors": "GCP credentials validation failed: Permission denied on resource project my-gcp-project.",
    "invalid_attributes": []
}'''
[/responses]

#### Example cURL

```shell
[label Connect a Google Cloud project]
curl --request PATCH \
  --url https://telemetry.betterstack.com/api/v1/sources/96 \
  --header "Authorization: Bearer $TOKEN" \
  --header "Content-Type: application/json" \
  --data '{
    "gcp_project_id": "my-gcp-project",
    "gcp_project_number": "587153488274"
  }'
```

Metric discovery starts right after the project is connected. Available metrics appear in the source's Ingest tab within a few minutes.

[warning]
#### Getting a validation error?
Better Stack authenticates through Workload Identity Federation configured by the setup script or the Terraform module. Re-run it against the project if validation fails, and check that the project number matches the project ID.
[/warning]
