Google Cloud Functions
Fivetran users who signed up on or after July 22, 2025, no longer have access to Function connections. Older Fivetran users can continue to create and use Function connections as before. All our users can use Connector SDK to build custom connectors. Connector SDK provides a streamlined development experience, and we'll host your custom connector for you.
Google Cloud Functions is a serverless computing platform that runs code in response to events and automatically manages the compute resources required by that code.
Features
| Feature Name | Supported | Notes | 
|---|---|---|
| Capture deletes | check | softDeletefield in its response. | 
| History mode | ||
| Custom data | check | |
| Data blocking | check | |
| Column hashing | check | |
| Re-sync | check | |
| API configurable | check | API configuration | 
| Priority-first sync | ||
| Fivetran data models | ||
| Private networking | ||
| Authorization via API | check | 
Supported deployment models
We support the SaaS Deployment model for the connector.
Supported languages
Google Cloud Functions supports the following languages:
- Node.js
- Python
- Go
Function request and response
Fivetran uses HTTP requests for the Google Cloud Functions connector. For more information about how Fivetran syncs data from your cloud function, see our Sync overview documentation.
Request format
Fivetran's request has a standard format. It is a JSON object with following root fields:
- agentis an informational object.
- stateis a JSON object that contains cursors from the previous successful function execution. It is key to performing incremental updates. A cursor is a bookmark that marks the data Fivetran has already synced, for example, a timestamp, ID, or index. For the initial sync,- stateis an empty JSON object {}. Fivetran expects an updated- stateobject in every response.- For more information about the - stateobject, see How to Use the state Object.
- secrets(optional) is a JSON object that contains access keys or API keys for the upstream APIs. Secrets allow you to store information (API tokens or database passwords) that you don’t want to maintain in your code. We use encryption at rest to store the secrets. We pass the secrets into your function every time we call the function. Enter your secrets using a JSON format in the connection setup form.
- secrets(optional) is a JSON object that contains access keys or API keys for the upstream APIs. Secrets allow you to store information (API tokens or database passwords) that you don’t want to maintain in your code. We use encryption at rest to store the secrets. We pass the secrets into your function every time we call the function. Enter your secrets using a JSON format in the connection setup form.- For Google Cloud Functions connections created on or after August 9, 2023, in the connection setup form, click + Add secrets and then specify the key-value pairs. For example, if you want to pass the - secretsas- {'apiKey': 'yourApiKey', 'consumerKey': 'test'}, add a key-value pair for each entry in the JSON structure. From all the key-value pairs, we construct the JSON object and then pass it to the function. For example, if you add- ('apiKey', 'yourApiKey'), ('consumerKey': 'test')as key-value pairs in the setup form, Fivetran passes- secrets: {'apiKey': 'yourApiKey', 'consumerKey': 'test'}to the function.- For Google Cloud Functions connections created before August 9, 2023, in the connection setup form, modify your secrets using a JSON format if it is already configured, otherwise use + Add secrets. For more information about the - secretsobject, see How to Use the secrets Object.
- customPayload(optional) is a JSON object as a set of key-value pairs that can be used to specify custom information. We pass the custom payloads into your function every time we call the function.
- setup_test(optional) is a boolean that lets the function know that Fivetran has invoked the function for the setup tests. The function runs a lightweight job to test the connectivity and returns a JSON object with the- hasMorefield set to- false.- We don't add this field to the request during syncs. 
- sync_id(optional) is the Fivetran sync identifier (UUID). You can find the- sync_idin your connection's dashboard logs and use it to debug and link function logs with connection logs.- When the - setup_testfield is set to- true, we add the- setup-testvalue to the- sync_idfield in the request. We call the function once with the- sync_id, and if we get an error, we then call the function without the- sync_id.
Example request
{
    "agent" : "Fivetran Google Cloud Functions Connector/<external_id>/<schema>",
    "state": {
        "cursor": "2020-01-01T00:00:00Z"
    },
    "secrets": {
        "apiToken": "abcdefghijklmnopqrstuvwxyz_0123456789"
    },
    "customPayload": {
      "samplePayload": "payload_value"
    },
    "sync_id": "468b681-c376-4117-bbc0-25d8ae02ace1"
}
In this example,
- external_idis the unique ID tied to your connection and is part of our code base.
- schemais the destination schema name you enter when you first set up your connection.
Response format
The response is a JSON object with following root fields:
- statecontains the updated state value(s).
- insertspecifies the entities and records to be inserted. Fivetran reads the data and infers the data type and the number of columns.
- delete(optional) specifies the entities and records to be deleted. Use this field to mark records as deleted. Fivetran doesn't delete the record; instead it marks the record as deleted by setting- _fivetran_deletedcolumn value to- true. If you specify the delete field, you must also specify the schema field.- Fivetran creates the - _fivetran_deletedcolumn in the destination table, only if your function response has the- deletefield.
- schema(optional) specifies primary key columns for each entity. You must be very consistent with the schema field and the primary key columns to avoid any unwanted behavior. If you don’t specify the schema, Fivetran appends the data.
- hasMoreis an indicator for Fivetran to make a follow-up call for fetching the next set of data. Fivetran keeps making repeated calls until it receives- hasMore = false.- For more information about the - hasMorefield, see How to Use the hasMore Object.
- softDelete(optional) specifies the list of entities to be soft deleted. Fivetran marks the records of these entities as deleted by setting the value of the- _fivetran_deletedcolumn to- true. We recommend that you use this field if you do not want to specify the individual records to be deleted in the- deletefield. If table is specified in both- deleteand- softDelete, delete section will be of no effect.
Example response
{
    "state": {
        "transaction": "2020-01-02T00:00:00Z",
    },
    "insert": {
        "transaction": [
            {"id":1, "amount": 100},
            {"id":3, "amount": 50}
        ],
    },
    "delete": {
        "transaction": [
            {"id":2},
        ],
    },
    "schema" : {
        "transaction": {
            "primary_key": ["id"]
        },
    },
    "hasMore" : false,
    "softDelete" : ["transaction"]
}
In this example,
- statecontains the- transactioncursor.
- transactionis an entity. Fivetran creates the- TRANSACTIONtable with- idand- amountcolumns.
- The function inserts records - 1and- 3into the- TRANSACTIONtable.
- The function marks record - 2as deleted from the- TRANSACTIONtable.
- hasMoreis set to- falseto indicate that there are no more records.
- softDeletemarks all the records of the- TRANSACTIONtable as deleted by setting the value of its- _fivetran_deletedcolumn to- true.
Custom error handling
Cloud functions may fail due to various reasons, including code execution errors, runtime issues, or internal errors. Add an error handling mechanism in your Google Cloud Function response to report an error on your Fivetran dashboard.
Design your Google Cloud Function to report an error:
- Use the - errorMessagefield in your response to indicate function execution errors. Fivetran creates an Error on the connection dashboard with your custom error message. For example, for the following response, Fivetran creates a- This is an errorError on your dashboard:- { "errorMessage": "This is an error" }
- Use the optional - errorTypeand- stackTracefields to pass additional information about the error. You must specify the- errorMessagefield to use the- errorTypeand- stackTracefields. You can use a String value for the- errorTypefield.- For example, for the following response, Fivetran creates an Error on your connection dashboard with the error type and stack trace details: - { "errorMessage": "name 'response' is not defined", "errorType": "NameError", "stackTrace": [ [ "/var/task/google_cloud_function.py", 35, "google_cloud_handler", "response['errorMessage'] = \"This is an error\"" ] ] }- Use a success or an error response as the responsefield value:- Success response containing data operations (for example, insertordelete).
- Error response (containing the errorMessage). If you includeerrorMessagein your response, the function displays that error and ignores any data operations you've specified.
 
- Success response containing data operations (for example, 
 
- Use a success or an error response as the 
The following sample function demonstrates how you can use custom error handling:
import json
import requests
def check_api(request):
   try:
       url = "https://api.example.com/resource"
       data = {"key1": "value1", "key2": "value2"}
       response = requests.get(url, data=data)
       response.raise_for_status()  # Raise an exception for non-200 status codes
       # Process successful response data here
   except requests.exceptions.RequestException as e:
       response = {}
       response["errorMessage"] = "name 'response' is not defined"
       response["errorType"] = "NameError"
       response["stackTrace"] = "--Stack trace of the error--"
       return response
Setup guide
Follow our step-by-step Google Cloud Functions setup guide to connect Google Cloud Functions with your destination.
View function logs
You can access detailed logs about your function and request processing. You can use these logs to track and debug errors:
- Access and analyze function logs in Google Cloud Logging. For more information, see Monitor your Cloud Function.
- Use Fivetran's Google Cloud Logging log service to connect and stream Fivetran log events.
- Fivetran generates and logs several types of data related to your account and destinations. You can use these logs to monitor your connections, track your usage, and audit changes. Use the Fivetran Platform Connector to deliver your logs to a schema in your destination.
Frequently asked questions
For more information about cloud functions, see the following: