//native
type Persona = {
apiKey: string;
};
/**
* Import Email Address Lists
* Bulk import email address List Items by uploading a CSV file.
Each row should be the details for a new List Item. The columns we allow are:
- value
- match_type (either 'email_address' or 'domain')
A match_type of 'email_address' will need to match the entire email address of an individual, while a match_type of 'domain' will match on the email address domain of an individual (i.e. all email addresses with domain 'gmail.com').
*/
export async function main(
auth: Persona,
body: {
data: {
attributes: {
file: { data?: string; filename?: string };
"list-id": string;
};
};
},
include?: string,
fields?: string,
Key_Inflection?: string,
Idempotency_Key?: string,
Persona_Version?: string,
) {
const url = new URL(
`https://api.withpersona.com/api/v1/importer/list-item/email-addresses`,
);
for (const [k, v] of [
["include", include],
["fields", fields],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const formData = new FormData();
for (const [k, v] of Object.entries(body)) {
if (v !== undefined) {
formData.append(k, String(v));
}
}
const headers: Record<string, string> = {
Authorization: `Bearer ${auth.apiKey}`,
"Content-Type": "application/json",
};
if (Key_Inflection) {
headers["Key-Inflection"] = Key_Inflection;
}
if (Idempotency_Key) {
headers["Idempotency-Key"] = Idempotency_Key;
}
if (Persona_Version) {
headers["Persona-Version"] = Persona_Version;
}
const response = await fetch(url, {
method: "POST",
headers,
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