//native
type Salesflare = {
apiKey: string;
};
/**
* List an account's messages
*
*/
export async function main(
auth: Salesflare,
account_id: string,
before: string | undefined,
after: string | undefined,
limit: string | undefined,
) {
const url = new URL(
`https://api.salesflare.com/accounts/${account_id}/messages`,
);
for (const [k, v] of [
["before", before],
["after", after],
["limit", limit],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
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