Sync Overquota API Data with Google Sheets
Source:R/sync_overquota_data_with_gsheet.R
sync_overquota_data_with_gsheet.RdThis function connects to an Overquota database, retrieves the
relevant data for a given srv_id, and syncs it to a specified Google
Sheet tab. If the tab doesn't exist, it creates one. If the tab exists, it
checks if the column structure matches, and either re-uploads the data or
appends new data based on the last record_id.
Details
The function performs the following steps:
Connects to the Overquota database using credentials from
g6tr.db.Retrieves and filters data from the
overquotastable based onsrv_id, and then unpacks fields as needed.Authenticates Google Sheets API access using an encrypted JSON secret.
Checks if the target tab in the Google Sheet exists:
If the tab doesn't exist, the function creates a new tab and uploads the data.
If the tab exists, the function checks if the column structure matches:
If the structure differs, the data in the tab is replaced.
If the structure matches, it filters the new data based on
record_idand appends only the new data.
Please make sure 'overquota-api@g6tr-automate.iam.gserviceaccount.com' has editor access to the sheet you provide.