Function not triggering on form submit

I’m trying to use netlify and its lambda function feature to run a node function . Based on , I have in my functions/submission-created.js:

const https = require("https");

exports.handler = async event => {

const email = '';
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 = '' + 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) => {

req.on('error', (e) => {



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 :

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">

And then let JavaScript do its trick:

var subscriptionForm = document.querySelector('.subscription-form')
subscriptionForm.addEventListener('submit', function(event)
    var XHR = new XMLHttpRequest()
    var formData = new FormData(subscriptionForm )
    XHR.addEventListener('load', function()
        // show success message
    XHR.addEventListener('error', function()
        // show error message
      }'POST', '')

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