//native
type Pipedrive = {
apiToken: string;
};
/**
* Add a discount to a deal
* Adds a discount to a deal changing, the deal value if the deal has one-time products attached.
*/
export async function main(
auth: Pipedrive,
id: string,
body: { description: string; amount: number; type: "percentage" | "amount" },
) {
const url = new URL(`https://api.pipedrive.com/api/v2/deals/${id}/discounts`);
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