Skip to content

Instantly share code, notes, and snippets.

@JoeKarlsson
Last active August 15, 2023 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoeKarlsson/3fbb8ec02960d0b2604dba849f508890 to your computer and use it in GitHub Desktop.
Save JoeKarlsson/3fbb8ec02960d0b2604dba849f508890 to your computer and use it in GitHub Desktop.
Send data to Tinybird from Google Sheets

Google Sheets to Tinybird Integration

This project enables seamless integration between Google Sheets and Tinybird, allowing users to send data directly from Sheets to Tinybird's API. By automating data transfer, users can efficiently manage data workflows, analyze information, and create real-time data pipelines. Why This Is Useful

  • Automated Data Transfer: Eliminate manual data entry by automatically sending data from Google Sheets to Tinybird.
  • Real-time Analysis: Enable real-time data analysis by connecting your Google Sheets with Tinybird's powerful analytics engine.
  • Flexible Workflows: Customize data structures and create different triggers according to your needs.
  • Ease of Use: Leverage Google Sheets as a familiar interface to manage and transfer your data.

Prerequisites

  • A Google Sheet containing the data you want to send to Tinybird.
  • Tinybird Account: You need to have an account with Tinybird to obtain an API token.

Instructions

1. Sign Up for Tinybird

Create a Tinybird account and follow their onboarding process to set up your environment.

2. Obtain Your Tinybird API Token

Go to your Tinybird dashboard to get your API token. This token will be used to authenticate your requests to Tinybird.

3. Open Your Google Sheet

Open the Google Sheet where you want to run the script.

4. Access the Script Editor

Go to the menu bar at the top and click on Extensions > Apps Script. This will open the script editor in a new tab.

5. Write or Paste the Script

In the script editor, write or paste the script from code.gs and replace YOUR_API_TOKEN with the token you obtained from Tinybird.

6. Save the Script

Click the floppy disk icon or press Ctrl + S (or Cmd + S on a Mac) to save your script.

7. Run the Script

Click the play (triangle) button on the toolbar at the top. You might be prompted to grant permissions the first time you run the script.

8. Check for Errors or Logs

If there are any errors, they will appear in the "Execution log" tab at the bottom. You can also use Logger.log() statements in your code to log messages, viewable in the "Logs" tab (accessible from View > Logs).

Contributing

If you find any issues or have suggestions for improvements, please submit an issue or a pull request.

License

This code is available under the MIT license. See the LICENSE file for more details.

function sendDataToTinybird() {
// 1. Get Data from the Sheet
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var rows = sheet.getRange('A1:C2').getValues(); // Modify this range as needed
// 2. Define the options common to all requests
var headers = {
Authorization: 'Bearer YOUR_AUTH_TOKEN' // Replace with your token
};
rows.forEach(function(row) {
// Create the payload for this row
var payload = JSON.stringify({
property1: row[0],
property2: row[1],
property3: row[2],
// Add more properties as needed
});
// Define the options for this request
var options = {
method: 'post',
contentType: 'application/json',
headers: headers,
payload: payload,
muteHttpExceptions: true // To get full response on error
};
var eventName = 'google_sheets'; // change this to your specific event name
// Make the request
var response = UrlFetchApp.fetch(
'https://api.tinybird.co/v0/events?name=' + eventName,
options
);
// Log the response
Logger.log(response.getContentText());
})
}
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Tinybird')
.addItem('Send Data to Tinybird', 'sendDataToTinybird')
.addToUi();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment