//native
type Salesflare = {
apiKey: string;
};
/**
* List stages
*
*/
export async function main(
auth: Salesflare,
id: string | undefined,
name: string | undefined,
pipeline_id: string | undefined,
pipeline_name: string | undefined,
order_by: string | undefined,
) {
const url = new URL(`https://api.salesflare.com/stages`);
for (const [k, v] of [
["id", id],
["name", name],
["pipeline.id", pipeline_id],
["pipeline.name", pipeline_name],
["order_by", order_by],
]) {
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