Skip to content

Instantly share code, notes, and snippets.

@PaulieScanlon
Created October 10, 2022 08:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PaulieScanlon/444ca57620a5fb4e146738832123848d to your computer and use it in GitHub Desktop.
Save PaulieScanlon/444ca57620a5fb4e146738832123848d to your computer and use it in GitHub Desktop.
Create the Serverless Function
const { GoogleSpreadsheet } = require('google-spreadsheet');
const doc = new GoogleSpreadsheet(process.env.GOOGLE_SHEET_ID);
export default async function handler(req, res) {
const {
query: { id }
} = req;
try {
if (!id) {
throw new Error();
}
await doc.useServiceAccountAuth({
client_email: process.env.GOOGLE_SERVICE_ACCOUNT_EMAIL,
private_key: process.env.GOOGLE_PRIVATE_KEY.replace(/\\n/gm, '\n')
});
res.status(200).json({ message: 'A ok!' });
} catch (error) {
res.status(500).json(error);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment