Edits history of script submission #18008 for ' Update a product (pipedrive)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Pipedrive = {
      apiToken: string;
    };
    /**
     * Update a product
     * Updates product data.
     */
    export async function main(
      auth: Pipedrive,
      id: string,
      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/${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