//native
type Pipedrive = {
apiToken: string;
};
/**
* Get all products
* Returns data about all products.
*/
export async function main(
auth: Pipedrive,
owner_id: string | undefined,
ids: string | undefined,
filter_id: string | undefined,
cursor: string | undefined,
limit: string | undefined,
sort_by: "id" | "name" | "add_time" | "update_time" | undefined,
sort_direction: "asc" | "desc" | undefined,
custom_fields: string | undefined,
) {
const url = new URL(`https://api.pipedrive.com/api/v2/products`);
for (const [k, v] of [
["owner_id", owner_id],
["ids", ids],
["filter_id", filter_id],
["cursor", cursor],
["limit", limit],
["sort_by", sort_by],
["sort_direction", sort_direction],
["custom_fields", custom_fields],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
"x-api-token": auth.apiToken,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 235 days ago