
Hey guys, I'm currently setting up a create contact action in studio.
This is my edited script: const token = CONFIG.BREVO_API_KEY; let list_id = CONFIG.BREVO_LIST_ID; list_id = Number(list_id);
const API_ENDPOINT = https://api.brevo.com/v3/contacts; const HEADERS = { 'content-type': 'application/json', 'accept': 'application/json', 'api-key': token };
let email = CONTACT.email ""; let first_name = CONTACT.name ? CONTACT.name : (CONTACT.email ? CONTACT.email.split("@")[0] : CONTACT.phone); let last_name = CONTACT.name "";
let raw = JSON.stringify({ "email": email, "attributes": { "FNAME": first_name, "LNAME": last_name }, "listIds": [list_id] })
const OPTIONS = { method: "POST", headers: HEADERS, body: raw, redirect: "follow" };
async function createContact() { const response = await fetch(API_ENDPOINT, OPTIONS).then(res=>res.text()); return response; }
try { let contact = await createContact(); return console.log("Contact Data", contact); } catch (error) { return console.log("Error Occured", error.message); }
What variables do I need to enter for email and name to create the contact? I've tried several options, none of them worked. Thanks for any help