This app will allow you to import data from a Google sheet, into a specified Perch collection. The app uses Perch's scheduled tasks in order to import the data every so often. This can be configured within the app.
To get this app up and running, it requires a few steps:
- Install this app folder into
your_perch_folder/addons/apps/
cd
intorg_sheets
folder in the terminal (or if you're in VS Code, right-click the folder and Open in Terminal)- Run
composer install
- Generate a
credentials.json
by following the Step 1 of the instructions here. Add thecredentials.json
file inside the newly created app folder,rg_sheets
- Run
php create_token.php
and follow the instructions in the terminal to generate atoken.json
file to allow authentication - You should be good to go!
The magic happens in RGSheets_Import.class.php
file. In here, you can edit two main variables:
collection
- the collection you want to import totemplatePath
- the path to your collection's template relative to Perch's template folderspreadsheetId
- the ID of the spreadsheet, e.ghttps://docs.google.com/spreadsheets/d/1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms/edit#gid=0
would beBxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms
spreadsheetRange
- this is the range of data you want to pull from the sheet. In the example,Sheet1!A2:F
, Sheet1 is the sheet name, A2 is the column/row you want to start from, and F is the end column to get every single row in the sheet.- To map the data to the collection, you can do the following to make the first column to
name
. Of course, you can add more, as per Perch's import docs:
$Importer->add_item([
'name' => $item[0],
]);
- By default, it's set to update the spreadsheet every 15 minutes (if your cron runs that often). You can adjust this by changing the
scheduled_tasks.php
file, replacing the15
with the specified minutes. You can read more about Perch's scheduled tasks, here.