Netlify function: Deletion of form submissions not working

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

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?

Please let us know the site name to investigate :slight_smile:

Hmm, not sure what might be going on there. Are you saying that code worked for you yesterday and not today? If you’ve never used it successfully before, might be best to ask the person who wrote the code if they can still get it to work; we didn’t write it and generally don’t support your custom source code - we guide you in debugging, don’t debug for you :slight_smile:

But if you are saying it worked for you recently and then stopped, please let us know more about the timeline there so we can see if something changed on our side.

It worked before and the script was not changed. Looking at the exact dates, I see that submissions stopped being deleted around November 21st 2022. …that’s when we did this change: Multilingual website always shows English content on the contact form custom success page - #2 by hillary

However, even with this information, we were not able to resolve this. Any ideas on your end?

If you’ve changed form names, maybe now you’d need to specify a form ID: Netlify API documentation and switch to this endpoint listFormSubmissions. Form ID can be found here: https://app.netlify.com/sites/<site-name>/forms/<form-id>