Test submission-created function

Hey! I created a function that should be triggered when a form is submitted. I named it submission-created.

When I test locally, with netlify dev, it works as expected. I’m testing with postman. However, after deploying it, I try sending requests to the endpoint and I don’t get any response. And in the function log in the ui, there is no event logged, is like the function is never been triggered.

How do I test that function?

Hey @guayom, IDK if I can help, but if I could see your script, I might be able to. I’m more than willing to try, and I’m sure others would like to see it as well (for the purposes of assisting you).

Sure, nothing too crazy, it’s something like this:

const axios = require("axios");
const { GET_RESPONSE_TOKEN } = process.env;

exports.handler = async (event, context, callback) => {
  const { email, name } = JSON.parse(event.body).payload.data;
  const data = {
    email,
    name,
    campaign: {
      campaignId: `stringWithId`
    },
    customFieldValues: [
      {
        customFieldId: "Vr5wqx",
        value: ["Website"]
      }
    ]
  };

  const options = {
    headers: {
      "Content-Type": "application/json",
      "X-Auth-Token": `api-key ${GET_RESPONSE_TOKEN}`
    }
  };

  try {
    const response = await axios.post(
      "https://api.getresponse.com/v3/contacts",
      data,
      options
    );
    return {
      statusCode: 200,
      body: JSON.stringify({ response: response.statusText })
    };
  } catch (error) {
    const errorData = error.response.data;
    return ({
      "statusCode": errorData.httpStatus,
      body: errorData.message
    });
  }
};

It works if I submit a form. But I want to test by sending requests directly to the endpoint using Postman.

Ah, not intuitive but here’s what’s going on:

You’ll have to make a second copy of the function named something else to test directly in production. Those event-triggered functions are only executed by us upon the event happening and cannot be externally executed as you’re trying.

1 Like