A simple serverless integration to help you send Moltin order data (including order items) to Google BigQuery.
📚 Moltin API reference — 📚 BigQuery API reference
-
A Google project with a dataset and two tables created. One table will receive orders and the other, order items. Your orders table should have a schema matching the field names in the
filterOrderJson
function inmapping.js
, your order items table schema should match the field names in thefilterItemJson
in the same mapping file. -
A Google KMS keyring and key.
-
Serverless CLI installed (
npm install -g serverless
)
Clone the repository:
git clone [email protected]:moltin/integration-examples.git
Install dependencies with Yarn
cd integration-examples/sync-orders-to-bigQuery
yarn
Using your Google keyring and key, encrypt your Moltin client secret. You can find the reference for KMS encryption here
In the file serverless.yml
, add values to the environment
section, make sure you add the encrypted version of the Moltin Client Secret.
Make sure you have Serverless configured to work with Google but when creating the service account, add KMS permissions too. You will end up with a JSON file. Create a folder in the root of this project called .gcloud
and add the JSON file there.
Make sure the stage
in the provider
section of serverless.yml
is set to DEV
or PROD
depending on whether you are testing or deploying to production. This blog post covers the purpose of stages.
Run sls deploy
and note the deployed endpoint logged out by the CLI.
There is a single handler function in this repository. It's called updateOrders
and is found in index.js
. It takes no arguments, and will push new and updated orders within the last day from Moltin to BigQuery. It will delete any orders already in BigQuery that might cause duplicates after the new batch is pushed.
When the deployed endpoint is called via GET, updateOrders
will run for you. Should you want to automate this, in https://console.cloud.google.com/cloudscheduler, you can set up a job to GET the deployed endpoint at a frequency of your choosing!