Moltin -> BigQuery
A simple serverless integration to help you send Moltin order data (including order items) to Google BigQuery.
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
mapping.js, your order items table schema should match the field names in the
filterItemJsonin the same mapping file.
A Google KMS keyring and key.
Serverless CLI installed (
npm install -g serverless)
1. Download the example
Clone the repository:
git clone email@example.com:moltin/integration-examples.git
Install dependencies with Yarn
cd integration-examples/sync-orders-to-bigQuery yarn
3. Configure your ENV variables
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.
3. Configure Serverless
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
PROD depending on whether you are testing or deploying to production. This blog post covers the purpose of stages.
4. Deploy to Google Cloud Functions
sls deploy and note the deployed endpoint logged out by the CLI.
5. How to use
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!