Edits history of script submission #17951 for ' Add an installment to a deal (pipedrive)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Pipedrive = {
      apiToken: string;
    };
    /**
     * Add an installment to a deal
     * Adds an installment to a deal.
    
    An installment can only be added if the deal includes at least one one-time product. 
    If the deal contains at least one recurring product, adding installments is not allowed.
    
    Only available in Advanced and above plans.
    
     */
    export async function main(
      auth: Pipedrive,
      id: string,
      body: { description: string; amount: number; billing_date: string },
    ) {
      const url = new URL(
        `https://api.pipedrive.com/api/v2/deals/${id}/installments`,
      );
    
      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