//native
type Brevo = {
apiKey: string;
};
/**
* Create a contact
* Creates new contacts on Brevo. Contacts can be created by passing either - 1. email address of the contact (email_id), 2. phone number of the contact (to be passed as "SMS" field in "attributes" along with proper country code), For example- {"SMS":"+91xxxxxxxxxx"} or {"SMS":"0091xxxxxxxxxx"} 3. ext_id
*/
export async function main(
auth: Brevo,
body: {
email?: string;
ext_id?: string;
attributes?: {};
emailBlacklisted?: false | true;
smsBlacklisted?: false | true;
listIds?: number[];
updateEnabled?: false | true;
smtpBlacklistSender?: string[];
},
) {
const url = new URL(`https://api.brevo.com/v3/contacts`);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
"api-key": auth.apiKey,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 428 days ago