//native
type Brevo = {
apiKey: string;
};
/**
* Import contacts
* It returns the background process ID which on completion calls
the notify URL that you have set in the input.
**Note**:
- Any contact attribute that doesn't exist in your account will be ignored at import end.
*/
export async function main(
auth: Brevo,
body: {
fileUrl?: string;
fileBody?: string;
jsonBody?: { email?: string; attributes?: {} }[];
listIds?: number[];
notifyUrl?: string;
newList?: { listName?: string; folderId?: number };
emailBlacklist?: false | true;
disableNotification?: false | true;
smsBlacklist?: false | true;
updateExistingContacts?: false | true;
emptyContactsAttributes?: false | true;
},
) {
const url = new URL(`https://api.brevo.com/v3/contacts/import`);
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