
Understanding and debugging your Fivetran custom connector is not straightfoward, with many online tutorials excluding the key component of data API's... pagination. After reading this blog you will have a better understanding of the expected behaviour between Fivetran and your custom connector when pagination is thrown into the mix.
A Fivetran custom connector is a cloud hosted function that can be set up on a cloud platform of your choice, which allows you to load data into Fivetran with a API Fivetran does not natively support.
Like standard connectors, custom connectors have a number of benefits:
Use Fivetran's Function connectors if:
Fivetran . Fivetran Custom Connector. (n.d.). Retrieved May 26, 2022, from https://fivetran.com/docs/functions
State Management
State is a JSON object that contains cursors from the previous successful Fivetran executions run.
https://fivetran.com/docs/functions/faq/use-state-object
https://fivetran.com/docs/functions/faq/use-secrets-object
Potential Issues to Consider
Fivetran Pagination
Fivetran pagination allows your lambda function to specify if there is more data to be collected, this is achieved using the hasMore boolean return.
When hasMore = True, state is updated as normal, however, Fivetran immediately calls the lambda with the updated state. This will keep occurring until hasMore = False, which then resets Fivetran to its default state.
https://fivetran.com/docs/functions/faq/use-hasmore-flag
Example Expected function payload
{
state: {
cursor: '2020-01-01',
paginationCounter: 0
},
secrets: Object
}
Example Expected Connector response format
state: {
cursor: cursorPoint,
paginationCounter: 1
},
insert: {
Table: apiResponseJson
},
schema: {
Table: {
primary_key: ['some_unique_key']
}
},
hasMore: boolean
}
}

For the sake of this example and readability, the return JSON from the api call will be summarised as apiJsonResponse
FivetranCall
state: {}
Connector Response
{
state: {
lastUpdate: ''
paginationCounter: 1
},
insert: {
apiJsonResponseTable: apiJsonResponse
},
schema: {
apiJsonResponseTable: {
primary_key: ['id']
}
},
hasMore: True
}
Initial API sync with no state, API call is getting all data with no state and has returned a paginated response
Key response features State:
lastUpdate as paginated query has not been completedhasMore = TrueFivetranCall
state: {
lastUpdate: '',
paginationCounter: 1
}
Connector Response
{
state: {
lastUpdate: '',
paginationCounter: 2
},
insert: {
apiJsonResponseTable: apiJsonResponse
},
schema: {
apiJsonResponseTable: {
primary_key: ['id']
}
},
hasMore: True
}
Paginating through the API response for initial sync
Key response features State:
FivetranCall
state: {
lastUpdate: '',
paginationCounter: 2
}
Connector Response
{
state: {
lastUpdate: '2020-01-01',
paginationCounter: 0
},
insert: {
apiJsonResponseTable: apiJsonResponse
},
schema: {
apiJsonResponseTable: {
primary_key: ['id']
}
},
hasMore: False
}
Paginating through the API response for initial sync
Key response features State:
lastUpdate Set as paginated query has been completedFivetranCall
state: {
lastUpdate: '2020-01-01',
paginationCounter: 0
}
Connector Response
{
state: {
lastUpdate: '2020-01-02',
paginationCounter: 0
},
insert: {
apiJsonResponseTable: apiJsonResponse
},
schema: {
apiJsonResponseTable: {
primary_key: ['id']
}
},
hasMore: False
}
Fivetran Sync with LastUpdate State
Key response features State:
FivetranCall
state: {
lastUpdate: '2020-01-02',
paginationCounter: 0
}
Connector Response
state: {
lastUpdate: '2020-01-03',
paginationCounter: 0
},
insert: {
apiJsonResponseTable: apiJsonResponse
},
schema: {
apiJsonResponseTable: {
primary_key: ['id']
}
},
hasMore: False
})
}
Fivetran Sync with LastUpdate State
Key response features State:
lastUpdate updated, query has been completedFor a full working example see Fivetran's documentation
https://fivetran.com/docs/functions/aws-lambda/sample-functions
https://fivetran.com/docs/functions
If you have any questions or need help with setting up your own connector, feel free to poke us