Edits history of script submission #17949 for ' Add a product to a deal (pipedrive)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Pipedrive = {
      apiToken: string;
    };
    /**
     * Add a product to a deal
     * Adds a product to a deal, creating a new item called a deal-product.
     */
    export async function main(
      auth: Pipedrive,
      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`);
    
      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