//native
type Pipedrive = {
apiToken: string;
};
/**
* Add a product
* Adds a new product to the Products inventory. For more information, see the tutorial for adding a product.
*/
export async function main(
auth: Pipedrive,
body: { name: string } & {
code?: string;
description?: string;
unit?: string;
tax?: number;
category?: number;
owner_id?: number;
is_linkable?: false | true;
visible_to?: 1 | 3 | 5 | 7;
prices?: {}[];
} & {
billing_frequency?:
| "one-time"
| "annually"
| "semi-annually"
| "quarterly"
| "monthly"
| "weekly";
} & { billing_frequency_cycles?: number },
) {
const url = new URL(`https://api.pipedrive.com/api/v2/products`);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-api-token": auth.apiToken,
},
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 235 days ago