Thanks for the response! I was able to figure it out by toying with Postman. Form submission triggers a build hook, which runs this code. The only problem now is that I’m getting the error described here:
“git ref refs/heads/master does not exist or you do not have permission”
const fetch = require('node-fetch');
var fs = require('fs');
require("dotenv").config()
const formID = "5ff0f18977371a0007907109"
const placeholder = "NA"
var requestOptions = {
method: 'GET',
redirect: 'follow'
};
fetch(`https://api.netlify.com/api/v1/forms/${formID}/submissions?access_token=${process.env.NETLIFY_ACCESS_TOKEN}`, requestOptions)
.then(response => response.text())
.then(function (data) {
data = JSON.parse(data)
data.forEach(submission => {
fs.writeFile(`public/${submission.first_name}-${submission.last_name}.vcf`,
`
BEGIN:VCARD
VERSION:3.0
PRODID:-//Apple Inc.//iPhone OS 13.1.3//EN
N:${submission.first_name};${submission.last_name};;;
...
END:VCARD
`
, function (err) {
if (err) throw err;
console.log('Saved!');
})
})
})
.catch(error => console.log('error', error))