I’m setting up a Lambda function that will handle adding people to a List/Segment via API like in the example here: https://developers.klaviyo.com/en/reference/add-members.
Here is my snippet of code:
//url is in format of 'https://a.klaviyo.com/api/v2/list/LIST_ID/members?api_key=API_KEY'
exports.handler = async function(event) {
console.log('Received event:', JSON.stringify(event, null, 2));
const options = {
method: 'POST',
headers: {Accept: 'application/json', 'Content-Type': 'application/json'},
body: JSON.stringify(event),
};
const promise = await new Promise(function(resolve, reject) {
https.get(url, options, (res) => {
res.on('data', (d) => {console.log('response:', d.toString())});
resolve(res.statusCode)
}).on('error', (e) => {
console.log('error:', e.toString());
reject(Error(e))
})
});
console.log("HELLO?");
console.log(promise);
return promise
}
//results
2022-03-05T20:08:20.031Z 8f81d290-144e-4c44-a590-ad3b77f05c42 INFO Received event: {
"profiles": {
"email": "george.washington@klaviyo.com"
}
}
2022-03-05T20:08:20.276Z 8f81d290-144e-4c44-a590-ad3b77f05c42 INFO response: {"detail":"profiles is a required parameter."}
2022-03-05T20:08:20.276Z 8f81d290-144e-4c44-a590-ad3b77f05c42 INFO HELLO?
2022-03-05T20:08:20.277Z 8f81d290-144e-4c44-a590-ad3b77f05c42 INFO 400
I am providing input in the following format:
{
"profiles": {
"email": "george.washington@klaviyo.com"
}
}
This call would work in Postman, but not on AWS lambda. Am I missing something else?