This topic was automatically generated from Slack. You can find the original thread here.
@U05A7KLNALC Say i have 200 rows of data in google sheet, now i want to transfer them into notion database, how do i loop these rows of data and transfer it?
This topic was automatically generated from Slack. You can find the original thread here.
@U05A7KLNALC Say i have 200 rows of data in google sheet, now i want to transfer them into notion database, how do i loop these rows of data and transfer it?
To transfer data from a Google Sheet to a Notion database, you can use the Google Sheets and Notion actions in Pipedream. Here’s a step-by-step guide: 1. Create a new workflow in Pipedream. 2. Add a trigger, like an HTTP trigger or a Scheduler trigger, depending on when you want the data transfer to happen. 3. Add a Google Sheets action to “Read Worksheet” from the Google Sheet containing your data. Connect your Google account and select the appropriate Sheet and Worksheet. 4. Add a Notion action to “Query Database” to get the Notion database you want to add the data to. Connect your Notion account and select the appropriate Database ID. 5. Add a code step to loop through the rows of data from the Google Sheet and create pages in the Notion database using the “Create Page” action. Here’s an example of the code step: ```
const rows = steps.read_worksheet.data.rows; for (const row of rows) { await steps.create_page.$run({ database_id: steps.query_database.data.id, properties: { // Map the Google Sheet columns to the Notion database properties // Replace “ColumnName” and “NotionPropertyName” with the actual names “NotionPropertyName”: { “title”: [ { “text”: { “content”: row[“ColumnName”], }, }, ], }, }, }); }
give me a python version
To transfer data from a Google Sheet to a Notion database using Python, you can use the google-auth
, google-api-python-client
, and notion-client
libraries. First, install them using pip: bash pip install google-auth google-auth-oauthlib google-auth-httplib2 google-api-python-client notion-client
Then, you can use the following Python script to transfer the data: ```
import os from google.oauth2 import service_account from googleapiclient.discovery import build from notion_client import Client # Set up Google Sheets API SERVICE_ACCOUNT_FILE = “path/to/your/service_account_key.json” SCOPES = [“https://www.googleapis.com/auth/spreadsheets.readonly”] creds = service_account.Credentials.from_service_account_file(SERVICE_ACCOUNT_FILE, SCOPES) sheets_api = build(“sheets”, “v4”, credentials=creds) # Set up Notion API notion = Client(auth=“your_notion_api_key”) # Read data from Google Sheet spreadsheet_id = “your_spreadsheet_id” sheet_name = “your_sheet_name” range_name = f"{sheet_name}!A1:Z200" # Adjust the range as needed result = sheets_api.spreadsheets().values().get(spreadsheetId=spreadsheet_id, range=range_name).execute() rows = result.get(“values”, []) # Transfer data to Notion database notion_database_id = “your_notion_database_id” for row in rows: new_page = { “NotionPropertyName”: { “title”: [{“text”: {“content”: row[0]}}], }, # Add more properties as needed } notion.pages.create(parent={“database_id”: notion_database_id}, properties=new_page)
isn’t there any loop node in pipedream?
In Pipedream, you can use loops within a code step to iterate through data. There isn’t a separate “loop node,” but you can achieve looping functionality using JavaScript within a code step. For example, you can use a for
loop or forEach
to iterate through an array of data and perform actions for each item. Here’s a simple example of using a for
loop in a code step: ```
const data = [“item1”, “item2”, “item3”]; for (const item of data) { console.log(item); }
will pipedream have ‘loop’ step in the future? i tried messed with the code but got no luck, i have to do it in zapier then…
There is no “Read Worksheet” from google sheet option for the non-python version of this answer.