Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const {BigQuery} = require('@google-cloud/bigquery');
- let datasetId='' //enter the Big Query Dataset ID
- let tableName='' //enter the Big Query table Name
- exports.webhook2bq = (req, res) => {
- try{
- const bigquery = new BigQuery();
- const dataset = bigquery.dataset(datasetId);
- const table = dataset.table(tableName);
- let time = new Date();
- let data = req.method === 'POST' ? req.body : req.query;
- console.log(data)
- table.insert({
- TIMESTAMP: time,
- DATA: JSON.stringify(data)
- })
- res.status(200).send(JSON.stringify(data));
- } catch(e) {
- console.log(e);
- res.status(400).send(JSON.stringify(e));
- return e;
- };
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement