Edits history of script submission #17947 for ' Add a new stage (pipedrive)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Pipedrive = {
      apiToken: string;
    };
    /**
     * Add a new stage
     * Adds a new stage, returns the ID upon success.
     */
    export async function main(
      auth: Pipedrive,
      body: {
        name: string;
        pipeline_id: number;
        deal_probability?: number;
        is_deal_rot_enabled?: false | true;
        days_to_rotten?: number;
      },
    ) {
      const url = new URL(`https://api.pipedrive.com/api/v2/stages`);
    
      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