Hey Team,
I have follow the API reference and set up my code as below:
const client = require("klaviyo-sdk");
var defaultClient = client.ApiClient.instance;
// Configure API key authorization: ApiKeyAuth
const ApiKeyAuth = defaultClient.authentications['ApiKeyAuth'];
ApiKeyAuth.apiKey = "MY_API_KEY";
app.post('/',(req,res) =>{
const firstname = req.body.firstName;
const lastname = req.body.lastName;
const phoneNumber = req.body.Phone;
const Email = req.body.email;
console.log(firstname, lastname, phoneNumber, Email);
const url = 'https://a.klaviyo.com/api/v2/list/MY_LIST_ID/members?api_key=MY_API_KEY';
const options = {
method: 'POST',
headers: {accept: 'application/json', 'content-type': 'application/json'},
body: JSON.stringify({
profiles: [{email: Email}, {phone_number: phoneNumber}, {FNAME: firstname}, {LNAME: lastname}]
})
};
fetch(url, options)
.then(res => res.json())
.then(json => console.log(json))
.catch(err => console.error('error:' + err));
})
But the terminal responded as
{
detail: 'email or phone number is a required field for each profile'
}
I have tested my List id and API key in Postman and it works fine. Why is this? I have input the email and phone number, also configured SMS notification in my account. Does any know how to fix this?