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.