Function not triggering on form submit

I’m trying to use netlify and its lambda function feature to run a node function . Based on https://css-tricks.com/using-netlify-forms-and-netlify-functions-to-build-an-email-sign-up-widget/ , I have in my functions/submission-created.js:

const https = require("https");


exports.handler = async event => {

const email = 'bill66666@mailinator.com';
const asking = '70000';

var formData = {
    'email': email,
    'first_name': '',
    'last_name': asking,
    'lists[]': '11111'
};
var encoded = await Object.entries(formData).map(([k, v]) => `${k}=${encodeURIComponent(v)}`).join("&");

var endpoint = 'https://api.sendfox.com/contacts/?' + encoded;

const options = {
    method: 'POST',
    headers: {
    'Authorization': 'Bearer XXXXXXXXX ',
    'Content-Type': 'application/json',
    }

};

const req = await https.request(endpoint, options, (res) => {
    await console.log('statusCode:', res.statusCode);
    await console.log('headers:', res.headers);

    res.on('data', (d) => {
    process.stdout.write(d);
    });
});

req.on('error', (e) => {
    console.error(e);
});
req.end();

}

return;

I’ve tested the code without the

exports.handler = async event => {...} function 

and it works when run as a node script at the command line.

The package structure looks like:

enter image description here

here is the repo :

https://github.com/kc1/test2

However when I submit the form on page offer.html, it runs till the async code block but does nor execute anything inside it. What am I doing wrong?

I haven’t used Netlify functions, so, I am not sure what’s happening. However, while you wait for someone to answer for the functions part, would it be possible for you to use an AJAX form instead?

You’d just have to create a simple form, say, like this:

<form class = "subscription-form" autocomplete = "off">
  <input type = "email" class = "email-field" required>
  <button type = "submit">
    Subscribe
  </button>
</form>

And then let JavaScript do its trick:

var subscriptionForm = document.querySelector('.subscription-form')
subscriptionForm.addEventListener('submit', function(event)
  {
    event.preventDefault()
    var XHR = new XMLHttpRequest()
    var formData = new FormData(subscriptionForm )
    XHR.addEventListener('load', function()
      {
        // show success message
      }
    XHR.addEventListener('error', function()
      {
        // show error message
      }
    XHR.open('POST', 'https://api.sendfox.com/contacts/?')
    XHR.send(formData)
  }

If you need JSON output only, you can also convert the formData to a JSON.