Edits history of script submission #17979 for ' Get details of a person (pipedrive)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Pipedrive = {
      apiToken: string;
    };
    /**
     * Get details of a person
     * Returns the details of a specific person. Fields `ims`, `postal_address`, `notes`, `birthday`, and `job_title` are only included if contact sync is enabled for the company.
     */
    export async function main(
      auth: Pipedrive,
      id: string,
      include_fields:
        | "next_activity_id"
        | "last_activity_id"
        | "open_deals_count"
        | "related_open_deals_count"
        | "closed_deals_count"
        | "related_closed_deals_count"
        | "participant_open_deals_count"
        | "participant_closed_deals_count"
        | "email_messages_count"
        | "activities_count"
        | "done_activities_count"
        | "undone_activities_count"
        | "files_count"
        | "notes_count"
        | "followers_count"
        | "won_deals_count"
        | "related_won_deals_count"
        | "lost_deals_count"
        | "related_lost_deals_count"
        | "last_incoming_mail_time"
        | "last_outgoing_mail_time"
        | "marketing_status"
        | "doi_status"
        | undefined,
      custom_fields: string | undefined,
    ) {
      const url = new URL(`https://api.pipedrive.com/api/v2/persons/${id}`);
      for (const [k, v] of [
        ["include_fields", include_fields],
        ["custom_fields", custom_fields],
      ]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          "x-api-token": auth.apiToken,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 235 days ago