//native
type Salesflare = {
apiKey: string;
};
/**
* Create a contact
* When payload is an array you will get an array back, if just an object or an array with 1 item you get an object back
*/
export async function main(auth: Salesflare, force: string | undefined) {
const url = new URL(`https://api.salesflare.com/contacts`);
for (const [k, v] of [["force", force]]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "POST",
headers: {
Authorization: "Bearer " + auth.apiKey,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.text();
}
Submitted by hugo697 235 days ago