Hi, I’m trying to create a contact in my contact list from a NextJs application.
The contact is created correctly but there are custom attributes that are not created.
For example, I have a field called STATE of list type that can contain ‹ Client › | ‹ Inactive › | ‹ Lead › | ‹ Negotiation ›, but it is not saved. The attributes: WHATSAPP, COMPANY, SOURCE are not saved either.
email: string;
name: string;
phone?: string; // Phone
whatsapp?: string; // WhatsApp
company?: string; // Company
status?: "CLIENT" | "INACTIVE" | "LEAD" | "NEGOTIATION"; // Status
}) {
try {
const contactsApi = new brevo.ContactsApi();
contactsApi.setApiKey(
brevo.ContactsApiApiKeys.apiKey,
process.env.BREVO_DACS_API_KEY as string
);
const contact = new brevo.CreateContact();
contact.email = lead.email;
// Set the attributes
contact.attributes = {
FIRSTNAME: lead.name,
EMAIL: lead.email,
PHONE: lead.phone || "", // Phone
WHATSAPP: lead.whatsapp || "", // WhatsApp
COMPANY: lead.company || "", // Company
CREATION_DATE: new Date().toISOString(), // Server date in ISO format// Time zone
STATUS: lead.status || "LEAD", // Default status
};
// Make sure the list ID is a number
contact.listIds = [Number(process.env.BREVO_CONTACT_LIST_ID)];
// Create the contact
const response = await contactsApi.createContact(contact);
console.log("Contact created successfully:", JSON.stringify(response));
} catch (error) {
console.error("Error creating contact:", error);
}
}escribe o pega el código aquí
Thank you in advance for any help you can give me
Regards,
Yhonatan