Documentation

Documentation

  • Getting Started
  • Core Concepts
  • Using Fivetran
  • Usage-Based Pricing
  • Connectors
  • Applications
  • Databases
  • Files
  • Events
  • Functions
    • AWS Lambda
    • Azure Functions
      • Setup Guide
      • Sample Functions
      • Release Notes
    • Google Cloud Functions
    • Functions Troubleshooting
    • Release Notes
  • Destinations
  • Partner-Built
  • Transformations
  • Logs
  • Security
  • REST API
  • Local Data Processing (HVR 6)
  • Release Notes
RSS
Release notes RSS
HVR 5 Documentation
HVR 5 Documentation
  • Support
  • Sign In
Edit on GitHub

Azure Functions link

Azure Functions is a serverless computing platform that runs code in response to events and automatically manages the compute resources required by that code.


Featureslink

Feature NameSupportedNotes
Capture deletescheck The function must include the softDelete field in its response.
Custom datacheck All tables and fields
Data blockingcheck Column level
Column hashingcheck
Re-synccheck Connector level
History
API configurablecheckAPI configuration
Priority-first sync
Fivetran data models
Private networking

Supported languageslink

Azure Functions supports the following languages:

  • C#
  • JavaScript
  • F#
  • Java *
  • PowerShell *
  • Python *
  • TypeScript *

* Supported in Microsoft's Azure Functions 2.x and later. For more information about supported languages, see Supported languages in Azure Functions.


Function request and responselink

Fivetran uses HTTP requests for the Azure Functions connector. For more information about how Fivetran syncs data from your cloud function, see our Sync overview documentation.

Request formatlink

Fivetran's request has a standard format. It is a JSON object with following root fields:

  • agent is an informational object.

  • state is 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, state is an empty JSON object {}. Fivetran expects an updated state object in every response.

    For more information about the state object, 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 connector setup form.

    IMPORTANT: For Azure Functions connectors created on or after August 9, 2023, in the connector setup form, click + Add secrets and then specify the key-value pairs. For example, if you want to pass the secrets as {'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 Azure 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 Azure function.

    NOTE: For Azure Functions connectors created before August 9, 2023, in the connector setup form, modify your secrets using a JSON format if it is already configured, otherwise use + Add secrets. For more information about the secrets object, 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 hasMore field set to false.

    NOTE: 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_id in your connector's dashboard logs and use it to debug and link function logs with connector logs.

    IMPORTANT: We don't add this field to the request when the setup_test field is set to true.

Example request

{
    "agent" : "Fivetran Azure 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"
}
content_copy

In this example,

  • external_id is the unique ID tied to your connector. You can find the ID in your connector setup form.
  • schema is the destination schema name you enter when you first set up your connector.

Response formatlink

The response is a JSON object with following root fields:

  • state contains the updated state value(s).
  • insert specifies 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_deleted column value to true. If you specify the delete field, you must also specify the schema field.

    Fivetran creates the _fivetran_deleted column in the destination table, only if your function response has the delete field.

  • 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.
  • hasMore is 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 hasMore field, 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_deleted column to true. We recommend that you use this field if you do not want to specify the individual records to be deleted in the delete field. If table is specified in both delete and 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"]
}
content_copy

In this example,

  • state contains the transaction cursor.

  • transaction is an entity. Fivetran creates the TRANSACTION table with id and amount columns.

  • The function inserts records 1 and 3 into the TRANSACTION table.

  • The function marks record 2 as deleted from the TRANSACTION table.

  • hasMore is set to false to indicate that there are no more records.

  • softDelete marks all the records of the TRANSACTION table as deleted by setting the value of its _fivetran_deleted column to true.

IMPORTANT: Make sure to add the "Content-Type" as "application/json" in the response header. For more information about adding "Content-Type" to the response header, see our sample function request.

Custom error handlinglink

Cloud functions may fail due to various reasons, including code execution errors, runtime issues, or internal errors. Add an error handling mechanism in your Azure function response to report an error on your Fivetran dashboard.

Design your Azure function to report an error:

  • Use the errorMessage field in your response to indicate function execution errors. Fivetran creates an Error on the connector dashboard with your custom error message. For example, for the following response, Fivetran creates a This is an error Error on your dashboard:

    {
    "errorMessage": "This is an error"
    }
    content_copy
  • Use the errorType and stackTrace fields to pass additional information about the error. You must specify the errorMessage field to use the errorType and stackTrace fields. For example, for the following response, Fivetran creates an Error alert on your dashboard with the error type and stack trace details:

    {
    "errorMessage": "name 'response' is not defined",
    "errorType": "NameError",
    "stackTrace": [
        [
        "/var/task/azure_function.py",
        35,
        "azure_handler",
        "response['errorMessage'] = \"This is an error\""
        ]
    ]
    }
    content_copy

Setup guidelink

Follow our step-by-step Azure Functions setup guide to connect Azure Functions with your destination using Fivetran connectors.


Frequently asked questionslink

For more information about cloud functions, see the following:

  • Can Custom Data be Exchanged between Fivetran and a Cloud Function
  • How Can I Upsert Data Using a Cloud Function
  • How Can I View Detailed Logs for My Cloud Function

Questions?

We're always happy to help with any other questions you might have! Send us an email.

    Thanks for your feedback!
    Was this page helpful?