Edits history of script submission #17941 for ' Add a follower to an organization (pipedrive)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Pipedrive = {
      apiToken: string;
    };
    /**
     * Add a follower to an organization
     * Adds a user as a follower to the organization.
     */
    export async function main(
      auth: Pipedrive,
      id: string,
      body: { user_id: number },
    ) {
      const url = new URL(
        `https://api.pipedrive.com/api/v2/organizations/${id}/followers`,
      );
    
      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