Last year I’ve implemented a Netlify function to remove form submissions from Netlify servers (for GDPR conformity). Back then, I followed the instructions on
- Using Netlify Functions to Delete Form Submissions - Adrian Payne | Frontend Dev Blog
- netlify-lambda - npm
Deletion of incoming requests worked well for a couple of months and stopped working about 2.5 months ago (I just saw some form submissions in the back-end, dating back about that time). Now I am trying to fix this, and am a bit stuck.
Log
The log for the submission-created function for my latests tests shows:
No results found for query
The form gets submitted upon my tests, I can see them in the app.netlify.com GUI.
Directory structure:
My directory structure:
.
├── netlify
│ └── functions
│ └── submission-created.js
├── netlify.toml
├── node_modules
├── package.json
├── package-lock.json
├── README.md
├── _site
├── _src
│ ├── assets
│ ├── _data
│ ├── _includes
...
package.json
{
"name": "REDACTED",
"version": "1.0.1",
"description": "",
"main": "",
"scripts": {
"start": "eleventy --serve",
"build": "eleventy",
"postinstall": "netlify-lambda install",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "REDACTED"
},
"keywords": [],
"author": "REDACTED",
"license": "ISC",
"dependencies": {
"eleventy-sass": "~2.1.7",
"netlify": "~13.1.2",
"netlify-cli": "~12.10.0"
},
"devDependencies": {
"@11ty/eleventy": "^1.0.2",
"html-minifier": "~4.0.0",
"netlify-lambda": "^2.0.15"
}
}
submissions-created.js
const NetlifyAPI = import('netlify')
exports.handler = async function (event, context) {
const client = new NetlifyAPI(process.env.NETLIFY_API_ACCESS_TOKEN)
const submissions = await client
.listSiteSubmissions({
site_id: process.env.SITE_ID,
})
.catch((e) => console.log('Error getting submissions', e))
if (submissions.length) {
for (i = 0; i < submissions.length; i++) {
await client.deleteSubmission({ submission_id: submissions[i].id })
}
return {
statusCode: 200,
body: 'Submissions deleted',
}
} else {
return {
statusCode: 200,
body: 'No submissions to delete',
}
}
}
What am I missing? Did something change?