//native
type Pipedrive = {
apiToken: string;
};
/**
* Update the product attached to a deal
* Updates the details of the product that has been attached to a deal.
*/
export async function main(
auth: Pipedrive,
id: string,
product_attachment_id: string,
body: {
product_id?: number;
item_price?: number;
quantity?: number;
tax?: number;
comments?: string;
discount?: number;
is_enabled?: false | true;
tax_method?: "exclusive" | "inclusive" | "none";
discount_type?: "percentage" | "amount";
product_variation_id?: number;
} & {
billing_frequency?:
| "one-time"
| "annually"
| "semi-annually"
| "quarterly"
| "monthly"
| "weekly";
} & { billing_frequency_cycles?: number } & { billing_start_date?: string },
) {
const url = new URL(
`https://api.pipedrive.com/api/v2/deals/${id}/products/${product_attachment_id}`,
);
const response = await fetch(url, {
method: "PATCH",
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