So you want to automate a table-to-table import in QuickBase. Well, here’s a nifty little command-line script that uses the QuickBase PHP SDK to do just that.
How it works
When run from the command-line, the php scripts accepts two paramaters: dbID of the table with the saved import, and then the importID of the import you wish to run. With these two params, the script can execute the QuickBase API_RunImport api call.
How to setup the import as a cron
This script can be setup just as any other cron you may run. The example below outputs the results of the cron (success or fail) to a log file. If you’ve got multiple imports you want to automate, you’ll just duplicate the call to the import script with different dbIDs and importIDs.
# | +------------- hour (0 - 23)
# | | +---------- day of month (1 - 31)
# | | | +------- month (1 - 12)
# | | | | +---- day of week (0 - 7) (Sunday=0 or 7)
# | | | | |
0 17 * * * /usr/bin/php /path/to/import-script.php DBID_HERE IMPORT_ID >> /var/log/www-cron-log
include('library/qb.php');
$quickbase = new QuickBase('YOUR_USER','YOUR_PASS', false, $argv[1]);
if($quickbase->errcode < 1) {
$results = $quickbase->api_run_import($argv[2]);
}
if($results->errcode < 1) {
echo "Successful Import at " . date("F j, Y, g:i a") . "\n"; }
else {
echo "Error: " . $results->errdetail . " at " . date("F j, Y, g:i a") . "\n";
}
No Comments